-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from NthPortal/eventbus
Fix threading and switch to Google EventBus
- Loading branch information
Showing
16 changed files
with
250 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/github/nthportal/uhc/events/MainListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
import com.github.nthportal.uhc.UHCPlugin; | ||
import com.github.nthportal.uhc.core.Config; | ||
import com.github.nthportal.uhc.util.CommandUtil; | ||
import com.google.common.base.Function; | ||
import com.google.common.eventbus.Subscribe; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MainListener { | ||
public final UHCPlugin plugin; | ||
|
||
public MainListener(UHCPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Subscribe | ||
public void onPlayerDeath(UHCPlayerDeathEvent event) { | ||
List<Function<String, String>> replacements = new ArrayList<>(); | ||
replacements.add(CommandUtil.replacementFunction(CommandUtil.ReplaceTargets.PLAYER, event.player.getName())); | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_DEATH, replacements); | ||
} | ||
|
||
@Subscribe | ||
public void onCountdownStart(UHCCountdownStartEvent event) { | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_COUNTDOWN_START); | ||
} | ||
|
||
@Subscribe | ||
public void onCountdownMark(UHCCountdownMarkEvent event) { | ||
List<Function<String, String>> replacements = new ArrayList<>(); | ||
replacements.add(CommandUtil.replacementFunction(CommandUtil.ReplaceTargets.COUNTDOWN_MARK, String.valueOf(event.countdownMark))); | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_COUNTDOWN_MARK, replacements); | ||
} | ||
|
||
@Subscribe | ||
public void onStart(UHCStartEvent event) { | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_START); | ||
} | ||
|
||
@Subscribe | ||
public void onStop(UHCStopEvent event) { | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_STOP); | ||
} | ||
|
||
@Subscribe | ||
public void onPause(UHCPauseEvent event) { | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_PAUSE); | ||
} | ||
|
||
@Subscribe | ||
public void onResume(UHCResumeEvent event) { | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_RESUME); | ||
} | ||
|
||
@Subscribe | ||
public void onEpisodeStart(UHCEpisodeStartEvent event) { | ||
List<Function<String, String>> replacements = new ArrayList<>(); | ||
replacements.add(CommandUtil.replacementFunction(CommandUtil.ReplaceTargets.EPISODE, String.valueOf(event.getEpisodeNumber()))); | ||
replacements.add(CommandUtil.replacementFunction(CommandUtil.ReplaceTargets.MINUTES, String.valueOf(event.getMinutesElapsed()))); | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_EPISODE_START, replacements); | ||
|
||
// Run episode-specific commands | ||
CommandUtil.executeMappedCommandsMatching(plugin, Config.Events.ON_START_EP_NUM, event.getEpisodeNumber()); | ||
} | ||
|
||
@Subscribe | ||
public void onEpisdeEnd(UHCEpisodeEndEvent event) { | ||
List<Function<String, String>> replacements = new ArrayList<>(); | ||
replacements.add(CommandUtil.replacementFunction(CommandUtil.ReplaceTargets.EPISODE, String.valueOf(event.getEpisodeNumber()))); | ||
replacements.add(CommandUtil.replacementFunction(CommandUtil.ReplaceTargets.MINUTES, String.valueOf(event.getMinutesElapsed()))); | ||
CommandUtil.executeEventCommands(plugin, Config.Events.ON_EPISODE_END, replacements); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/github/nthportal/uhc/events/UHCCountdownMarkEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCCountdownMarkEvent { | ||
public final int countdownMark; | ||
|
||
public UHCCountdownMarkEvent(int countdownMark) { | ||
this.countdownMark = countdownMark; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/github/nthportal/uhc/events/UHCCountdownStartEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCCountdownStartEvent { | ||
public final int countingDownFrom; | ||
|
||
public UHCCountdownStartEvent(int countingDownFrom) { | ||
this.countingDownFrom = countingDownFrom; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/github/nthportal/uhc/events/UHCEpisodeEndEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCEpisodeEndEvent { | ||
private final int episodeNumber; | ||
private final int episodeLength; | ||
private final int minutesElapsed; | ||
|
||
public UHCEpisodeEndEvent(int episodeNumber, int episodeLength) { | ||
this.episodeNumber = episodeNumber; | ||
this.episodeLength = episodeLength; | ||
this.minutesElapsed = episodeNumber * episodeLength; | ||
} | ||
|
||
public int getEpisodeNumber() { | ||
return episodeNumber; | ||
} | ||
|
||
public int getEpisodeLength() { | ||
return episodeLength; | ||
} | ||
|
||
public int getMinutesElapsed() { | ||
return minutesElapsed; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/github/nthportal/uhc/events/UHCEpisodeStartEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCEpisodeStartEvent { | ||
private final int episodeNumber; | ||
private final int episodeLength; | ||
private final int minutesElapsed; | ||
|
||
public UHCEpisodeStartEvent(int episodeNumber, int episodeLength) { | ||
this.episodeNumber = episodeNumber; | ||
this.episodeLength = episodeLength; | ||
this.minutesElapsed = episodeLength * (episodeNumber - 1); | ||
} | ||
|
||
public int getEpisodeNumber() { | ||
return episodeNumber; | ||
} | ||
|
||
public int getEpisodeLength() { | ||
return episodeLength; | ||
} | ||
|
||
public int getMinutesElapsed() { | ||
return minutesElapsed; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/github/nthportal/uhc/events/UHCMinuteEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCMinuteEvent { | ||
public final int minuteNumber; | ||
|
||
public UHCMinuteEvent(int minuteNumber) { | ||
this.minuteNumber = minuteNumber; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/github/nthportal/uhc/events/UHCPauseEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCPauseEvent { | ||
public final long timeElapsed; | ||
|
||
public UHCPauseEvent(long timeElapsed) { | ||
this.timeElapsed = timeElapsed; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/github/nthportal/uhc/events/UHCPlayerDeathEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
public class UHCPlayerDeathEvent { | ||
public final Player player; | ||
|
||
public UHCPlayerDeathEvent(Player player) { | ||
this.player = player; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/github/nthportal/uhc/events/UHCResumeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCResumeEvent { | ||
public final long timeElapsed; | ||
|
||
public UHCResumeEvent(long timeElapsed) { | ||
this.timeElapsed = timeElapsed; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/github/nthportal/uhc/events/UHCStartEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.github.nthportal.uhc.events; | ||
|
||
public class UHCStartEvent { | ||
} |
Oops, something went wrong.