diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java new file mode 100644 index 00000000..9bdd0916 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java @@ -0,0 +1,81 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.autostart; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.linkage.LinkedInstance; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; + +@Linked(LinkageType.COMMAND) +public class AutoStartCommand extends SWCommand { + + @LinkedInstance + private AutostartListener autostartListener; + + public AutoStartCommand() { + super("timer", "autostarttimer", "at", "autostart"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§etimer §8- §7Legt den AutostartTimer ins Inventar"); + } + + @Register + public void genericCommand(Player p) { + SWUtils.giveItemToPlayer(p, AutostartListener.WAND); + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (!AutostartListener.WAND.isSimilar(event.getItem())) { + return; + } + if (event.getClickedBlock() == null) { + return; + } + Player player = event.getPlayer(); + Region region = Region.getRegion(event.getClickedBlock().getLocation()); + if (region.isGlobal()) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return; + } + if (!region.hasType(RegionType.TESTBLOCK)) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return; + } + if (autostartListener.getRegionStartTime().containsKey(region)) { + player.sendMessage(BauSystem.PREFIX + "§eDer AutostartTimer wurde zurückgesetzt"); + } else { + player.sendMessage(BauSystem.PREFIX + "§eAutostartTimer gestartet"); + } + autostartListener.getRegionStartTime().put(region, TPSUtils.currentTick.get()); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java new file mode 100644 index 00000000..d21c9d19 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -0,0 +1,66 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.autostart; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.inventory.SWItem; +import lombok.Getter; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.inventory.ItemStack; + +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Linked(LinkageType.LISTENER) +public class AutostartListener implements Listener { + + public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eAutostartTimer", Arrays.asList("§eRechtsklick Block §8- §7Starte den Timer"), false, null).getItemStack(); + + @Getter + private Map regionStartTime = new HashMap<>(); + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + event.blockList().forEach(block -> { + Region region = Region.getRegion(block.getLocation()); + if (!regionStartTime.containsKey(region)) return; + if (!region.hasType(RegionType.TESTBLOCK)) return; + if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return; + long tickDiff = TPSUtils.currentTick.get() - regionStartTime.remove(region); + RegionUtils.message(region, BauSystem.PREFIX + "§eZeit §7bis zur §eExplosion §7am Gegner§8:§e " + new SimpleDateFormat("mm:ss SSSS").format(new Date(tickDiff * 50))); + RegionUtils.message(region, BauSystem.PREFIX + "§eZeitdifferenz in ticks §7bis 60 Sekunden§8:§e " + (1200 - tickDiff)); + RegionUtils.message(region, BauSystem.PREFIX + "§7Positiv, wenn zu wenig, negativ wenn zu viel"); + }); + } + +}