SteamWar/FightSystem
Archiviert
13
1
Dieser Commit ist enthalten in:
Chaoscaot 2020-12-07 23:38:14 +01:00
Ursprung 030bfbc6a1
Commit e431b1323c
3 geänderte Dateien mit 19 neuen und 106 gelöschten Zeilen

Datei anzeigen

@ -1,31 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
public class ArrowStopper_14 {
private ArrowStopper_14(){}
static int blockToId(Block block){
return net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS());
}
}

Datei anzeigen

@ -1,31 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
import org.bukkit.block.Block;
public class ArrowStopper_8 {
private ArrowStopper_8(){}
@SuppressWarnings("deprecation")
static int blockToId(Block block){
return block.getTypeId();
}
}

Datei anzeigen

@ -17,34 +17,33 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.listener;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerPickupArrowEvent;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.*; import java.util.*;
public class ArrowStopper implements StateDependent, Listener { public class ArrowStopper extends BasicListener {
private BukkitTask task; private BukkitTask task;
private static final HashMap<Entity, Location> LAST_LOCATION = new HashMap<>(); private static final HashMap<Entity, Location> LAST_LOCATION = new HashMap<>();
ArrowStopper() {
super(EnumSet.of(FightState.RUNNING));
}
public static void init() { public static void init() {
if(Config.ArrowTechhiderCollision == 0) if(Config.ArrowTechhiderCollision == 0)
return; return;
@ -52,16 +51,18 @@ public class ArrowStopper implements StateDependent, Listener {
} }
private void run() { private void run() {
Collection<Entity> arrows = Bukkit.getWorlds().get(0).getEntitiesByClasses(AbstractArrow.class);
if(arrows.isEmpty())
return;
for (Map.Entry<Entity, Location> e : LAST_LOCATION.entrySet()) { for (Map.Entry<Entity, Location> e : LAST_LOCATION.entrySet()) {
if(checkBlocks(e.getKey().getLocation().getBlock(), e.getValue().getBlock())) Entity entity = e.getKey();
e.getKey().remove(); if(checkBlocks(entity.getLocation().getBlock(), e.getValue().getBlock())){
entity.remove();
LAST_LOCATION.remove(entity);
}
else { else {
if(e.getKey().getTicksLived() <= Config.ArrowTechhiderCollision || if(entity.getTicksLived() > Config.ArrowTechhiderCollision ||
!((AbstractArrow) e.getKey()).isInBlock()) { ((AbstractArrow) entity).isInBlock() || entity.getLocation().equals(e.getValue())) {
LAST_LOCATION.put(e.getKey(), e.getKey().getLocation()); LAST_LOCATION.remove(entity);
}else {
LAST_LOCATION.replace(e.getKey(), e.getKey().getLocation());
} }
} }
} }
@ -69,46 +70,20 @@ public class ArrowStopper implements StateDependent, Listener {
@EventHandler() @EventHandler()
public void onEntityShootBow(EntityShootBowEvent event) { public void onEntityShootBow(EntityShootBowEvent event) {
if(!(event.getEntity() instanceof Player))
return;
LAST_LOCATION.put(event.getProjectile(), event.getEntity().getEyeLocation()); LAST_LOCATION.put(event.getProjectile(), event.getEntity().getEyeLocation());
} }
@EventHandler
public void onPlayerPickupArrow(PlayerPickupArrowEvent event) {
LAST_LOCATION.remove(event.getArrow());
}
@Override
public Set<FightState> enabled() {
return EnumSet.of(FightState.RUNNING);
}
@Override @Override
public void enable() { public void enable() {
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); super.enable();
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1); task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1);
} }
@Override @Override
public void disable() { public void disable() {
super.disable();
task.cancel(); task.cancel();
LAST_LOCATION.clear(); LAST_LOCATION.clear();
HandlerList.unregisterAll(this);
}
private static int blockToId(Block block){
switch(Core.getVersion()){
case 8:
case 9:
case 10:
case 12:
return ArrowStopper_8.blockToId(block);
case 14:
case 15:
default:
return ArrowStopper_14.blockToId(block);
}
} }
private boolean checkBlocks(Block start, Block end) { private boolean checkBlocks(Block start, Block end) {
@ -142,6 +117,6 @@ public class ArrowStopper implements StateDependent, Listener {
} }
private boolean checkBlock(Block block) { private boolean checkBlock(Block block) {
return Config.HiddenBlocks.contains(blockToId(block)); return Config.HiddenBlockTags.contains(block.getType().name());
} }
} }