-
Notifications
You must be signed in to change notification settings - Fork 14
Autojoin feature #57
base: master
Are you sure you want to change the base?
Autojoin feature #57
Changes from all commits
df7bed5
2fb1213
c74edc2
5e4c166
84d1333
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tc.oc.pgm.autojoin; | ||
|
||
import tc.oc.commons.bukkit.settings.SettingBinder; | ||
import tc.oc.commons.core.inject.HybridManifest; | ||
import tc.oc.pgm.match.inject.MatchModuleFixtureManifest; | ||
|
||
public class AutoJoinManifest extends HybridManifest { | ||
@Override | ||
protected void configure() { | ||
new SettingBinder(publicBinder()).addBinding().toInstance(AutoJoinSetting.get()); | ||
install(new MatchModuleFixtureManifest<AutoJoinMatchModule>(){}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package tc.oc.pgm.autojoin; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import tc.oc.commons.bukkit.settings.SettingManagerProvider; | ||
import tc.oc.pgm.events.ListenerScope; | ||
import tc.oc.pgm.events.PlayerChangePartyEvent; | ||
import tc.oc.pgm.join.JoinMatchModule; | ||
import tc.oc.pgm.join.JoinMethod; | ||
import tc.oc.pgm.match.MatchModule; | ||
import tc.oc.pgm.match.MatchPlayer; | ||
import tc.oc.pgm.match.MatchScope; | ||
|
||
import javax.inject.Inject; | ||
|
||
/** | ||
* New join feature that allows players to join without interfacing with GUI | ||
* with an AutoJoinSetting that allows players to use the legacy join feature | ||
* instead. | ||
*/ | ||
@ListenerScope(MatchScope.LOADED) | ||
public class AutoJoinMatchModule extends MatchModule implements Listener { | ||
private Set<MatchPlayer> joiningPlayers; | ||
private final SettingManagerProvider settingManagerProvider; | ||
private final JoinMatchModule joinMatchModule; | ||
|
||
@Inject public AutoJoinMatchModule(SettingManagerProvider settingManagerProvider, JoinMatchModule joinMatchModule) { | ||
this.joiningPlayers = new LinkedHashSet<>(); | ||
this.settingManagerProvider = settingManagerProvider; | ||
this.joinMatchModule = joinMatchModule; | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
joiningPlayers.clear(); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR) | ||
public void playerJoin(final PlayerChangePartyEvent event) { | ||
MatchPlayer player = event.getPlayer(); | ||
|
||
if(match.hasStarted()) return; | ||
|
||
if(event.getNewParty() == null) { | ||
joiningPlayers.remove(player); | ||
return; | ||
} | ||
|
||
if(event.getNewParty().isParticipatingType()) return; | ||
|
||
if(joiningPlayers.contains(player)) return; | ||
|
||
if(!settingManagerProvider.getManager(player.getBukkit()).getValue(AutoJoinSetting.get(), Boolean.class, true)) return; | ||
|
||
joiningPlayers.add(player); | ||
} | ||
|
||
public boolean shouldAutoJoin(MatchPlayer player) { | ||
return joiningPlayers.contains(player); | ||
} | ||
|
||
public void cancelAutojoin(MatchPlayer player) { | ||
joiningPlayers.remove(player); | ||
} | ||
|
||
public void requestJoin(MatchPlayer player) { | ||
joinMatchModule.requestJoin(player, JoinMethod.USER); | ||
} | ||
|
||
public void enterAllPlayers() { | ||
if(!joiningPlayers.isEmpty()) joiningPlayers.forEach(this::requestJoin); | ||
} | ||
|
||
public Stream<MatchPlayer> joiningPlayers() { | ||
return joiningPlayers.stream(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package tc.oc.pgm.autojoin; | ||
|
||
import me.anxuiz.settings.Setting; | ||
import me.anxuiz.settings.SettingBuilder; | ||
import me.anxuiz.settings.types.BooleanType; | ||
|
||
public class AutoJoinSetting { | ||
private static final Setting INSTANCE = new SettingBuilder() | ||
.name("AutoJoin").alias("aj") | ||
.summary("Automatically join a team when the match starts") | ||
.type(new BooleanType()) | ||
.defaultValue(true) | ||
.get(); | ||
|
||
public static Setting get() { | ||
return INSTANCE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.ClickType; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryCloseEvent; | ||
import org.bukkit.event.player.PlayerLocaleChangeEvent; | ||
|
@@ -40,6 +39,7 @@ | |
import tc.oc.commons.core.chat.Component; | ||
import tc.oc.commons.core.formatting.StringUtils; | ||
import tc.oc.pgm.PGMTranslations; | ||
import tc.oc.pgm.autojoin.AutoJoinMatchModule; | ||
import tc.oc.pgm.blitz.BlitzEvent; | ||
import tc.oc.pgm.classes.ClassMatchModule; | ||
import tc.oc.pgm.classes.ClassModule; | ||
|
@@ -96,15 +96,22 @@ public boolean matches(MaterialData material) { | |
private final ComponentRenderContext renderer; | ||
private final JoinMatchModule jmm; | ||
private final BlitzMatchModule bmm; | ||
private final AutoJoinMatchModule autoJoinMatchModule; | ||
private final boolean hasTeams; | ||
private final boolean hasClasses; | ||
|
||
private final Set<MatchPlayer> picking = new HashSet<>(); | ||
|
||
@Inject PickerMatchModule(ComponentRenderContext renderer, JoinMatchModule jmm, BlitzMatchModule bmm, Optional<TeamModule> teamModule, Optional<ClassModule> classModule) { | ||
@Inject PickerMatchModule(ComponentRenderContext renderer, | ||
JoinMatchModule jmm, | ||
BlitzMatchModule bmm, | ||
AutoJoinMatchModule autoJoinMatchModule, | ||
Optional<TeamModule> teamModule, | ||
Optional<ClassModule> classModule) { | ||
this.renderer = renderer; | ||
this.jmm = jmm; | ||
this.bmm = bmm; | ||
this.autoJoinMatchModule = autoJoinMatchModule; | ||
this.hasTeams = teamModule.isPresent(); | ||
this.hasClasses = classModule.isPresent(); | ||
} | ||
|
@@ -288,29 +295,43 @@ public void closeMonitoredInventory(final InventoryCloseEvent event) { | |
} | ||
|
||
@EventHandler | ||
public void rightClickIcon(final ObserverInteractEvent event) { | ||
if(event.getClickType() != ClickType.RIGHT) return; | ||
|
||
public void handleClickIcon(final ObserverInteractEvent event) { | ||
MatchPlayer player = event.getPlayer(); | ||
if(!canUse(player)) return; | ||
|
||
ItemStack hand = event.getClickedItem(); | ||
if(ItemUtils.isNothing(hand)) return; | ||
|
||
String displayName = hand.getItemMeta().getDisplayName(); | ||
if(displayName == null) return; | ||
|
||
if(hand.getType() == Button.JOIN.material) { | ||
event.setCancelled(true); | ||
if(canOpenWindow(player)) { | ||
showWindow(player); | ||
} else { | ||
// If there is nothing to pick, just join immediately | ||
jmm.requestJoin(player, JoinRequest.user()); | ||
} | ||
} else if(hand.getType() == Button.LEAVE.material) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the leave button? Does it still work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i simply refactored it and commented it out below |
||
event.setCancelled(true); | ||
jmm.requestObserve(player); | ||
if(hand.getType() != Button.JOIN.material) return; | ||
|
||
switch(event.getClickType()) { | ||
// Autojoin feature - Player left clicks the hat(cancels Autojoin) | ||
case LEFT: | ||
if(autoJoinMatchModule.shouldAutoJoin(player)) { | ||
autoJoinMatchModule.cancelAutojoin(player); | ||
} | ||
player.sendHotbarMessage(new Component(ChatColor.DARK_PURPLE).translate("autojoin.cancelled").bold(true)); | ||
break; | ||
case RIGHT: | ||
if(!canUse(player)) return; | ||
|
||
if(hand.getType() == Button.JOIN.material) { | ||
event.setCancelled(true); | ||
if(canOpenWindow(player)) { | ||
showWindow(player); | ||
} else { | ||
// If there is nothing to pick, just join immediately | ||
jmm.requestJoin(player, JoinRequest.user()); | ||
} | ||
// Removed until this has some use - currently does nothing | ||
//} else if(hand.getType() == Button.LEAVE.material) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you going to leave this here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretty sure that the button doesn't do anything, so i'll leave this here at the moment until we find some use for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but add a comment explaining that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep this in, I believe it is for ranked |
||
// event.setCancelled(true); | ||
// jmm.requestObserve(player); | ||
// | ||
} | ||
break; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the extra new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️