mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 18:55:17 +01:00
Fixed bugs with protection.
Added serializer adapter for the Flags hashmap in Island. Teams don't work. Need to work out why. PVP doesn't work correctly. It allows members to hit visitors anytime, but visitors can only hit others if PVP is off. This isn't how it is supposed to work!
This commit is contained in:
parent
6c2078fbec
commit
83d0848429
@ -89,6 +89,11 @@ public class BSkyBlock extends JavaPlugin {
|
||||
islandWorldManager = new IslandWorld(plugin);
|
||||
|
||||
getServer().getScheduler().runTask(plugin, () -> {
|
||||
|
||||
// Load Flags
|
||||
flagsManager = new FlagsManager(plugin);
|
||||
new Flags(plugin);
|
||||
|
||||
// Load islands from database
|
||||
islandsManager.load();
|
||||
|
||||
@ -98,9 +103,6 @@ public class BSkyBlock extends JavaPlugin {
|
||||
// Register Listeners
|
||||
registerListeners();
|
||||
|
||||
// Load Flags
|
||||
flagsManager = new FlagsManager(plugin);
|
||||
new Flags(plugin);
|
||||
|
||||
// Load addons
|
||||
addonsManager = new AddonsManager(plugin);
|
||||
|
@ -1,6 +1,13 @@
|
||||
package us.tastybento.bskyblock.api.configuration;
|
||||
|
||||
|
||||
/**
|
||||
* Convert from to S or to V
|
||||
* @author tastybento
|
||||
*
|
||||
* @param <S>
|
||||
* @param <V>
|
||||
*/
|
||||
public interface Adapter<S,V> {
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ import us.tastybento.bskyblock.Constants.GameType;
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ConfigEntry {
|
||||
|
||||
String path();
|
||||
String path() default "";
|
||||
String since() default "1.0";
|
||||
boolean overrideOnChange() default false;
|
||||
boolean experimental() default false;
|
||||
|
@ -0,0 +1,46 @@
|
||||
package us.tastybento.bskyblock.database.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.configuration.Adapter;
|
||||
import us.tastybento.bskyblock.api.flags.Flag;
|
||||
|
||||
/**
|
||||
* Serializes the {@link us.tastybento.bskyblock.database.objects.Island#getFlags() getFlags()} and
|
||||
* {@link us.tastybento.bskyblock.database.objects.Island#setFlags() setFlags()}
|
||||
* in {@link us.tastybento.bskyblock.database.objects.Island}
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class FlagSerializer implements Adapter<HashMap<Flag, Integer>, HashMap<String, Integer>> {
|
||||
|
||||
@Override
|
||||
public HashMap<Flag, Integer> convertFrom(Object from) {
|
||||
HashMap<Flag, Integer> result = new HashMap<>();
|
||||
MemorySection section = (MemorySection) from;
|
||||
for (String key : section.getKeys(false)) {
|
||||
Bukkit.getLogger().info("DEBUG: " + key + " = " + section.getInt(key));
|
||||
|
||||
result.put(BSkyBlock.getInstance().getFlagsManager().getFlagByID(key), section.getInt(key));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Integer> convertTo(Object to) {
|
||||
HashMap<String, Integer> result = new HashMap<>();
|
||||
HashMap<Flag, Integer> flags = (HashMap<Flag, Integer>)to;
|
||||
for (Entry<Flag, Integer> en: flags.entrySet()) {
|
||||
result.put(en.getKey().getID(), en.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ import org.bukkit.entity.Entity;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.configuration.ConfigEntry;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandLockEvent;
|
||||
@ -77,8 +78,11 @@ public class Island implements DataObject {
|
||||
private boolean spawn = false;
|
||||
|
||||
private boolean purgeProtected = false;
|
||||
//// Protection ////
|
||||
|
||||
//// Protection flags ////
|
||||
@ConfigEntry(adapter = FlagSerializer.class)
|
||||
private HashMap<Flag, Integer> flags = new HashMap<>();
|
||||
|
||||
private int levelHandicap;
|
||||
private Location spawnPoint;
|
||||
|
||||
|
@ -43,14 +43,13 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
private boolean createEventUser(Event e) {
|
||||
try {
|
||||
// Use reflection to get the getPlayer method if it exists
|
||||
|
||||
Method getPlayer = e.getClass().getMethod("getPlayer");
|
||||
if (getPlayer != null) {
|
||||
setUser(User.getInstance((Player)getPlayer.invoke(e)));
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e1) { e1.printStackTrace();}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -76,7 +75,7 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the event and sends the island public message to user unless silent is true
|
||||
* Cancels the event and sends the island protected message to user unless silent is true
|
||||
* @param e Event
|
||||
* @param silent - if true, message is not sent
|
||||
*/
|
||||
@ -85,7 +84,7 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
((Cancellable)e).setCancelled(true);
|
||||
if (user != null) {
|
||||
if (!silent)
|
||||
user.sendMessage("protection.public");
|
||||
user.sendMessage("protection.protected");
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
@ -147,7 +146,7 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
if (!createEventUser(e)) {
|
||||
// The user is not set, and the event does not hold a getPlayer, so return false
|
||||
// TODO: is this the correct handling here?
|
||||
Bukkit.getLogger().severe("Check island had no associated user!");
|
||||
Bukkit.getLogger().severe("Check island had no associated user! " + e.getEventName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -32,31 +33,31 @@ public class InventoryListener extends AbstractFlagListener {
|
||||
|
||||
/**
|
||||
* Prevents visitors picking items from inventories
|
||||
* @param event
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onMountInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getInventory().getHolder() == null) {
|
||||
public void onMountInventoryClick(InventoryClickEvent e) {
|
||||
if (e.getInventory().getHolder() == null) {
|
||||
return;
|
||||
}
|
||||
if (event.getInventory().getHolder() instanceof Animals) {
|
||||
checkIsland(event, event.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
||||
if (e.getInventory().getHolder() instanceof Animals) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
||||
}
|
||||
else if (event.getInventory().getHolder() instanceof Chest
|
||||
|| event.getInventory().getHolder() instanceof Dispenser
|
||||
|| event.getInventory().getHolder() instanceof Hopper
|
||||
|| event.getInventory().getHolder() instanceof Dropper
|
||||
|| event.getInventory().getHolder() instanceof ShulkerBox) {
|
||||
checkIsland(event, event.getInventory().getLocation(), Flags.CHEST);
|
||||
else if (e.getInventory().getHolder() instanceof Chest
|
||||
|| e.getInventory().getHolder() instanceof Dispenser
|
||||
|| e.getInventory().getHolder() instanceof Hopper
|
||||
|| e.getInventory().getHolder() instanceof Dropper
|
||||
|| e.getInventory().getHolder() instanceof ShulkerBox) {
|
||||
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.CHEST);
|
||||
}
|
||||
else if (event.getInventory().getHolder() instanceof Furnace) {
|
||||
checkIsland(event, event.getInventory().getLocation(), Flags.FURNACE);
|
||||
else if (e.getInventory().getHolder() instanceof Furnace) {
|
||||
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.FURNACE);
|
||||
}
|
||||
else if (event.getInventory().getHolder() instanceof BrewingStand) {
|
||||
checkIsland(event, event.getInventory().getLocation(), Flags.BREWING);
|
||||
else if (e.getInventory().getHolder() instanceof BrewingStand) {
|
||||
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.BREWING);
|
||||
}
|
||||
else if (event.getInventory().getHolder() instanceof Beacon) {
|
||||
checkIsland(event, event.getInventory().getLocation(), Flags.BEACON);
|
||||
else if (e.getInventory().getHolder() instanceof Beacon) {
|
||||
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.BEACON);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,10 +35,10 @@ public class ItemDropPickUpListener extends AbstractFlagListener {
|
||||
* Handle item pickup by visitors
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onVisitorDrop(EntityPickupItemEvent e) {
|
||||
public void onVisitorPickup(EntityPickupItemEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
// Disallow, but don't tell the player an error
|
||||
setUser(User.getInstance(e.getEntity())).checkIsland(e, e.getItem().getLocation(), Flags.ITEM_PICKUP, false);
|
||||
setUser(User.getInstance(e.getEntity())).checkIsland(e, e.getItem().getLocation(), Flags.ITEM_PICKUP, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import us.tastybento.bskyblock.api.flags.Flag;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
/**
|
||||
* TODO: PVP is different to other flags - it's either allowed for everyone or not allowed for everyone. Currently owners can hit visitors.
|
||||
* Handles PVP
|
||||
* @author tastybento
|
||||
*
|
||||
|
@ -512,7 +512,6 @@ public class TestBSkyBlock {
|
||||
Event e = new BlockBreakEvent(block, ownerOfIsland);
|
||||
Assert.assertTrue(fl.checkIsland(e, location, Flags.BREAK_BLOCKS, true));
|
||||
|
||||
// Set up an event with a random player
|
||||
Bukkit.getLogger().info("DEBUG: checking events - member");
|
||||
|
||||
Event e2 = new BlockBreakEvent(block, player);
|
||||
|
Loading…
Reference in New Issue
Block a user