Simplify multiversioning with removing fall-through code #188
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
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.listener;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
class PersonalKitCreator_14 {
|
||||||
|
private PersonalKitCreator_14(){}
|
||||||
|
|
||||||
|
static boolean hasAttributeModifier(ItemStack stack){
|
||||||
|
return stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is a part of the SteamWar software.
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@ -19,20 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.listener;
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerPickupArrowEvent;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
class PickupArrowListener_9 implements Listener {
|
||||||
|
|
||||||
public class SleepListener extends BasicListener{
|
@EventHandler
|
||||||
|
public void onArrowPickup(PlayerPickupArrowEvent e){
|
||||||
public SleepListener() {
|
e.setCancelled(true);
|
||||||
super(EnumSet.allOf(FightState.class));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onSleep(PlayerBedEnterEvent e) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -93,10 +93,10 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new TestListener();
|
new TestListener();
|
||||||
new NormalJoinListener();
|
new NormalJoinListener();
|
||||||
new RankedJoinListener();
|
new RankedJoinListener();
|
||||||
new SleepListener();
|
new GameplayListener();
|
||||||
new PersonalKitCreator();
|
new PersonalKitCreator();
|
||||||
if(Core.getVersion() > 8)
|
if(Core.getVersion() > 8)
|
||||||
new ExtendedInventoryListener();
|
new VersionDependentListener();
|
||||||
|
|
||||||
new EnterHandler();
|
new EnterHandler();
|
||||||
|
|
||||||
|
@ -20,23 +20,21 @@
|
|||||||
package de.steamwar.fightsystem.listener;
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.inventory.CraftItemEvent;
|
import org.bukkit.event.inventory.CraftItemEvent;
|
||||||
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupArrowEvent;
|
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public class ExtendedInventoryListener extends BasicListener {
|
public class GameplayListener extends BasicListener{
|
||||||
|
|
||||||
public ExtendedInventoryListener() {
|
public GameplayListener() {
|
||||||
super(EnumSet.allOf(FightState.class));
|
super(EnumSet.allOf(FightState.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onArrowPickup(PlayerPickupArrowEvent e){
|
public void onSleep(PlayerBedEnterEvent e) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +45,6 @@ public class ExtendedInventoryListener extends BasicListener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFurnace(FurnaceSmeltEvent e){
|
public void onFurnace(FurnaceSmeltEvent e){
|
||||||
e.setResult(new ItemStack(Material.AIR));
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,7 +46,6 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class PersonalKitCreator extends BasicListener {
|
public class PersonalKitCreator extends BasicListener {
|
||||||
@ -156,7 +155,7 @@ public class PersonalKitCreator extends BasicListener {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
//Check for attribute modifiers
|
//Check for attribute modifiers
|
||||||
if(Core.getVersion() >= 14 && stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers()){
|
if(Core.getVersion() >= 14 && PersonalKitCreator_14.hasAttributeModifier(stack)){
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen.");
|
Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
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.listener;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class VersionDependentListener extends BasicListener {
|
||||||
|
|
||||||
|
private final List<Listener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public VersionDependentListener() {
|
||||||
|
super(EnumSet.allOf(FightState.class));
|
||||||
|
if(Core.getVersion() > 8)
|
||||||
|
listeners.add(new PickupArrowListener_9());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable() {
|
||||||
|
for(Listener listener : listeners)
|
||||||
|
Bukkit.getPluginManager().registerEvents(listener, FightSystem.getPlugin());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable() {
|
||||||
|
for(Listener listener : listeners)
|
||||||
|
HandlerList.unregisterAll(listener);
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren