Ajout de l'event

This commit is contained in:
Maxlego08 2021-01-05 11:11:52 +01:00
parent 24e1482716
commit fb7b51e89b
6 changed files with 110 additions and 14 deletions

View File

@ -16,13 +16,15 @@ import org.bukkit.inventory.ItemStack;
import fr.maxlego08.zkoth.api.FactionListener;
import fr.maxlego08.zkoth.api.Koth;
import fr.maxlego08.zkoth.api.enums.LootType;
import fr.maxlego08.zkoth.api.enums.MessageType;
import fr.maxlego08.zkoth.api.event.events.KothCatchEvent;
import fr.maxlego08.zkoth.api.event.events.KothLooseEvent;
import fr.maxlego08.zkoth.api.event.events.KothSpawnEvent;
import fr.maxlego08.zkoth.api.event.events.KothWinEvent;
import fr.maxlego08.zkoth.save.Config;
import fr.maxlego08.zkoth.zcore.enums.Message;
import fr.maxlego08.zkoth.zcore.utils.Cuboid;
import fr.maxlego08.zkoth.zcore.utils.ZUtils;
import fr.maxlego08.zkoth.zcore.utils.builder.TimerBuilder;
public class ZKoth extends ZUtils implements Koth {
@ -212,7 +214,7 @@ public class ZKoth extends ZUtils implements Koth {
message = message.replace("%x%", String.valueOf(center.getBlockX()));
message = message.replace("%y%", String.valueOf(center.getBlockY()));
message = message.replace("%z%", String.valueOf(center.getBlockZ()));
message = message.replace("%capture%", String.valueOf(currentCaptureSeconds.get()));
message = message.replace("%capture%", TimerBuilder.getStringTime(this.currentCaptureSeconds == null ? 0 : currentCaptureSeconds.get()));
message = message.replace("%world%", center.getWorld().getName());
message = message.replace("%name%", this.name);
message = message.replace("%player%", this.currentPlayer == null ? "" : this.currentPlayer.getName());
@ -244,12 +246,13 @@ public class ZKoth extends ZUtils implements Koth {
if (event.isCancelled())
return;
broadcast(Message.ZKOHT_EVENT_LOOSE);
if (this.timerTask != null)
this.timerTask.cancel();
this.timerTask = null;
this.currentPlayer = null;
}
}
@ -271,26 +274,76 @@ public class ZKoth extends ZUtils implements Koth {
return;
}
broadcast(Message.ZKOHT_EVENT_CATCH);
int captureSeconds = event.getCaptureSeconds();
captureSeconds = captureSeconds < 0 ? 30 : captureSeconds;
this.currentCaptureSeconds = new AtomicInteger(captureSeconds);
Cuboid cuboid = getCuboid();
scheduleFix(1000, 1000, (task, isCancelled) -> {
scheduleFix(0, 1000, (task, isCancelled) -> {
this.timerTask = task;
if (!isCancelled) {
task.cancel();
return;
}
if (!isEnable) {
if (!this.isEnable) {
task.cancel();
return;
}
int tmpCapture = currentCaptureSeconds.getAndDecrement();
int tmpCapture = this.currentCaptureSeconds.getAndDecrement();
if (this.currentPlayer != null) {
if (!this.currentPlayer.isOnline() || !cuboid.contains(this.currentPlayer.getLocation()))
this.currentPlayer = null;
}
if (this.currentPlayer == null) {
KothLooseEvent kothLooseEvent = new KothLooseEvent(this.currentPlayer, this);
kothLooseEvent.callEvent();
if (kothLooseEvent.isCancelled())
return;
if (this.timerTask != null)
this.timerTask.cancel();
this.timerTask = null;
this.currentPlayer = null;
broadcast(Message.ZKOHT_EVENT_LOOSE);
return;
}
if (Config.displayMessageKothCap.contains(tmpCapture))
broadcast(Message.ZKOHT_EVENT_TIMER);
if (tmpCapture <= 0) {
KothWinEvent kothWinEvent = new KothWinEvent(this, this.currentPlayer);
kothWinEvent.callEvent();
if (kothWinEvent.isCancelled())
return;
task.cancel();
broadcast(Message.ZKOTH_EVENT_WIN);
//donner les loots
this.isEnable = false;
this.isCooldown = false;
this.currentPlayer = null;
this.timerTask = null;
this.currentCaptureSeconds = null;
}
});
}

View File

@ -0,0 +1,37 @@
package fr.maxlego08.zkoth.api.event.events;
import org.bukkit.entity.Player;
import fr.maxlego08.zkoth.api.Koth;
import fr.maxlego08.zkoth.api.event.CancelledKothEvent;
public class KothWinEvent extends CancelledKothEvent {
private final Koth koth;
private final Player player;
/**
* @param koth
* @param player
*/
public KothWinEvent(Koth koth, Player player) {
super();
this.koth = koth;
this.player = player;
}
/**
* @return the koth
*/
public Koth getKoth() {
return koth;
}
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
}

View File

@ -1,11 +1,16 @@
package fr.maxlego08.zkoth.save;
import java.util.Arrays;
import java.util.List;
import fr.maxlego08.zkoth.zcore.utils.storage.Persist;
import fr.maxlego08.zkoth.zcore.utils.storage.Saveable;
public class Config implements Saveable {
public static long playerMoveEventCooldown = 50;
public static List<Integer> displayMessageCooldown = Arrays.asList(300, 120, 60, 30, 10, 5, 4, 3, 2, 1);
public static List<Integer> displayMessageKothCap = Arrays.asList(300, 120, 60, 30, 10, 5, 4, 3, 2, 1);
/**
* static Singleton instance.

View File

@ -66,14 +66,15 @@ public enum Message {
ZKOTH_EVENT_WIN(MessageType.CENTER,
"§8§m-+------------------------------+-",
"",
"§d%player% §fof faction §7%faction §fhas just captured",
"§fthe koth, and §nwins §fthe event!",
"§d%player% §fof faction §7%faction% §fhas just captured",
"§fthe koth, and §nwins§f the event!",
"",
"§8§m-+------------------------------+-"
),
ZKOHT_EVENT_CATCH(MessageType.ACTION, "§d%player% §fjust started capturing the koth §n%name%§f. §8(§7%x%, %y%, %z%§8)"),
ZKOHT_EVENT_LOOSE(MessageType.ACTION, "§d%player% §fjust loose koth §n%name%§f. §8(§7%x%, %y%, %z%§8)"),
ZKOHT_EVENT_TIMER(MessageType.ACTION, "§fAnother §b%capture% §fbefore §d%player% §fwins the koth §n%name%§e. §8(§7%x%, %y%, %z%§8)"),
;

View File

@ -108,9 +108,9 @@ public abstract class MessageUtils extends LocationUtils {
* @param message
* @param args
*/
protected void broadcastAction(String message, Object... args) {
protected void broadcastAction(String message) {
for (Player player : Bukkit.getOnlinePlayers())
ActionBar.sendActionBar(player, String.format(message, args));
ActionBar.sendActionBar(player, message);
}
}

View File

@ -91,7 +91,7 @@ public class ActionBar {
Method var23 = message0.getClass().getDeclaredMethod("sendPacket", new Class[] { var5 });
var23.invoke(message0, new Object[] { var6 });
} catch (Exception message7) {
message7.printStackTrace();
// message7.printStackTrace();
}
}
}, 1);