1.0.0-SNAPSHOT-U185

+ Started to work on the AutoSpawnLocationHandler
This commit is contained in:
Charles 2019-01-07 21:13:20 +08:00
parent 5670fed1e9
commit 851c5f7785
3 changed files with 93 additions and 1 deletions

View File

@ -0,0 +1,91 @@
package com.songoda.epicbosses.handlers;
import com.songoda.epicbosses.autospawns.AutoSpawn;
import com.songoda.epicbosses.managers.files.AutoSpawnFileManager;
import com.songoda.epicbosses.utils.IHandler;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.ServerUtils;
import com.songoda.epicbosses.utils.StringUtils;
import com.songoda.epicbosses.utils.panel.base.IVariablePanelHandler;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.UUID;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 07-Jan-19
*/
public class AutoSpawnLocationHandler implements IHandler {
@Getter private final IVariablePanelHandler<AutoSpawn> panelHandler;
@Getter private AutoSpawnFileManager autoSpawnFileManager;
@Getter private final AutoSpawn autoSpawn;
@Getter private final Player player;
@Getter @Setter private boolean handled = false;
private Listener listener;
public AutoSpawnLocationHandler(Player player, AutoSpawn autoSpawn, AutoSpawnFileManager autoSpawnFileManager, IVariablePanelHandler<AutoSpawn> panelHandler) {
this.player = player;
this.autoSpawn = autoSpawn;
this.panelHandler = panelHandler;
this.autoSpawnFileManager = autoSpawnFileManager;
this.listener = getListener();
}
@Override
public void handle() {
ServerUtils.get().registerListener(this.listener);
}
private Listener getListener() {
return new Listener() {
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if(!uuid.equals(getPlayer().getUniqueId())) return;
if(isHandled()) return;
String input = event.getMessage();
if(input.equalsIgnoreCase("-")) {
input = null;
}
if(input == null) {
}
Location location = StringUtils.get().fromStringToLocation(input);
if(location == null) {
Message.Boss_AutoSpawn_InvalidLocation.msg(getPlayer(), input);
return;
}
autoSpawn.getIntervalSpawnData().setLocation(input);
getAutoSpawnFileManager().save();
event.setCancelled(true);
setHandled(true);
finish();
}
};
}
private void finish() {
AsyncPlayerChatEvent.getHandlerList().unregister(this.listener);
getPanelHandler().openFor(getPlayer(), getAutoSpawn());
}
}

View File

@ -27,6 +27,7 @@ public enum Message {
Boss_AutoSpawn_ToggleEditing("&b&lEpicBosses &8» &7You have toggled the editing mode for the &f{0}&7 auto spawn to &f{1}&7."),
Boss_AutoSpawn_NotCompleteEnough("&c&l(!) &cThe auto spawn is not set up enough to be enabled. Please make sure it has: &fA Spawn Entity(s) and Type&c before you try and enable the auto spawn."),
Boss_AutoSpawn_SpawnRate("&b&lEpicBosses &8» &7You have {0} the spawn rate of the auto spawn to &f{1}&7."),
Boss_AutoSpawn_InvalidLocation("&c&l(!) &cThe specified location string, &f{0}&c, is invalid. A correct example should be &fworld,10,150,-30&c . If you want to cancel the location update type &f- &cand you will be brought back to the settings menu."),
Boss_Create_EntityTypeNotFound("&c&l(!) &cThe specified entity type {0} was not found. If you think this is an error please contact &fAMinecraftDev&c."),
Boss_Create_InvalidArgs("&c&l(!) &cYou must use &n/boss create [name] [entity] &c to create a boss."),

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>1.0.0-U184</plugin.version>
<plugin.version>1.0.0-U185</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>