Skip to content

Commit

Permalink
Reverted back to IF 7 because of bugs on their side, improved protection
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Dec 6, 2020
1 parent 4562d3b commit fd7a015
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Islands.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<orderEntry type="library" name="WorldEdit" level="project" />
<orderEntry type="library" name="Vault" level="project" />
<orderEntry type="library" name="IF-0.8.0" level="project" />
<orderEntry type="library" name="IF-0.8.1" level="project" />
<orderEntry type="library" name="IF-0.7.2" level="project" />
</component>
</module>
Binary file added libs/IF-0.7.2.jar
Binary file not shown.
10 changes: 5 additions & 5 deletions src/me/aleksilassila/islands/GUIs/AdminGUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.aleksilassila.islands.GUIs;

import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.StaticPane;
import me.aleksilassila.islands.IslandsConfig;
import me.aleksilassila.islands.utils.BiomeMaterials;
Expand All @@ -26,8 +26,8 @@ public AdminGUI(Player player) {
}

@Override
public ChestGui getMainGui() {
ChestGui gui = new ChestGui(3, Messages.get("gui.admin.TITLE"));
public Gui getMainGui() {
Gui gui = new Gui(3, Messages.get("gui.admin.TITLE"));
gui.setOnTopClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));

addBackground(gui, Material.GRAY_STAINED_GLASS_PANE);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void showPlayerIslandsGui(String uuid) {

if (pane.getItems().size() > 0) pages.add(pane);

ChestGui gui = createPaginatedGUI(PAGE_HEIGHT, Messages.get("gui.admin.PLAYER_TITLE", displayName), pages);
Gui gui = createPaginatedGUI(PAGE_HEIGHT, Messages.get("gui.admin.PLAYER_TITLE", displayName), pages);

StaticPane back = new StaticPane(4, gui.getRows() - 1, 1, 1);

Expand Down
10 changes: 5 additions & 5 deletions src/me/aleksilassila/islands/GUIs/CreateGUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.aleksilassila.islands.GUIs;

import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.StaticPane;
import me.aleksilassila.islands.Islands;
import me.aleksilassila.islands.generation.Biomes;
Expand Down Expand Up @@ -43,7 +43,7 @@ public CreateGUI setOldCost(double cost) {
}

@Override
public ChestGui getMainGui() {
public Gui getMainGui() {
return createPaginatedGUI(PAGE_HEIGHT, Messages.get("gui.create.TITLE"), availableIslandPanes());
}

Expand Down Expand Up @@ -103,8 +103,8 @@ private List<StaticPane> availableIslandPanes() {
return panes;
}

private ChestGui getSizeGui(Biome biome) {
ChestGui gui = createPaginatedGUI(2, Messages.get("gui.create.SIZE_TITLE"), availableSizePanes("island " + subcommand + " " + (biome == null ? "RANDOM" : biome.name())));
private Gui getSizeGui(Biome biome) {
Gui gui = createPaginatedGUI(2, Messages.get("gui.create.SIZE_TITLE"), availableSizePanes("island " + subcommand + " " + (biome == null ? "RANDOM" : biome.name())));
gui.setOnTopClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));

if (plugin.econ != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/me/aleksilassila/islands/GUIs/GUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.aleksilassila.islands.GUIs;

import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import com.github.stefvanschie.inventoryframework.pane.Pane;
import org.bukkit.ChatColor;
Expand All @@ -17,7 +17,7 @@
import java.util.List;

public abstract class GUI {
public abstract ChestGui getMainGui();
public abstract Gui getMainGui();
public abstract Player getPlayer();

public void open() {
Expand Down Expand Up @@ -47,7 +47,7 @@ protected ItemStack createGuiItem(final Material material, final String name, bo
return item;
}

protected void addBackground(ChestGui gui, Material material) {
protected void addBackground(Gui gui, Material material) {
OutlinePane background = new OutlinePane(0, 0, 9, gui.getRows(), Pane.Priority.LOWEST);
background.addItem(new GuiItem(createGuiItem(material, "" + ChatColor.RESET, false)));
background.setRepeat(true);
Expand Down
12 changes: 6 additions & 6 deletions src/me/aleksilassila/islands/GUIs/IslandSettingsGUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.aleksilassila.islands.GUIs;

import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.StaticPane;
import me.aleksilassila.islands.IslandsConfig;
import me.aleksilassila.islands.utils.Messages;
Expand Down Expand Up @@ -33,8 +33,8 @@ public Player getPlayer() {
}

@Override
public ChestGui getMainGui() {
ChestGui gui = new ChestGui(3, Messages.get("gui.trust.TITLE"));
public Gui getMainGui() {
Gui gui = new Gui(3, Messages.get("gui.trust.TITLE"));
gui.setOnTopClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));

addBackground(gui, Material.GRAY_STAINED_GLASS_PANE);
Expand Down Expand Up @@ -112,7 +112,7 @@ public void showTrustedPlayersList() {
public void showPlayerMenu(OfflinePlayer offlinePlayer) {
String uuid = offlinePlayer.getUniqueId().toString();

ChestGui gui = new ChestGui(4, Messages.get("gui.trust.player.TITLE", offlinePlayer.getName()));
Gui gui = new Gui(4, Messages.get("gui.trust.player.TITLE", offlinePlayer.getName()));
gui.setOnTopClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));

addBackground(gui, Material.GRAY_STAINED_GLASS_PANE);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void showPlayerMenu(OfflinePlayer offlinePlayer) {
}

public void showIslandProtectionMenu() {
ChestGui gui = new ChestGui(4, Messages.get("gui.trust.global.TITLE"));
Gui gui = new Gui(4, Messages.get("gui.trust.global.TITLE"));
gui.setOnTopClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));

addBackground(gui, Material.GRAY_STAINED_GLASS_PANE);
Expand Down
10 changes: 5 additions & 5 deletions src/me/aleksilassila/islands/GUIs/PageGUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.aleksilassila.islands.GUIs;

import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.github.stefvanschie.inventoryframework.pane.Pane;
Expand All @@ -14,8 +14,8 @@
import java.util.List;

public abstract class PageGUI extends GUI {
protected ChestGui createPaginatedGUI(int pageHeight, String title, List<StaticPane> pages) {
ChestGui gui = new ChestGui(pageHeight, title);
protected Gui createPaginatedGUI(int pageHeight, String title, List<StaticPane> pages) {
Gui gui = new Gui(pageHeight, title);
gui.setOnTopClick(event -> event.setCancelled(true));

PaginatedPane pane = new PaginatedPane(0, 0, 9, pageHeight - 1);
Expand Down Expand Up @@ -72,7 +72,7 @@ protected ChestGui createPaginatedGUI(int pageHeight, String title, List<StaticP
return gui;
}

protected ChestGui addMainMenuButton(ChestGui gui) {
protected Gui addMainMenuButton(Gui gui) {
StaticPane pane = new StaticPane(4, gui.getRows() - 1, 1, 1);

pane.addItem(new GuiItem(createGuiItem(Material.BARRIER,
Expand Down
8 changes: 4 additions & 4 deletions src/me/aleksilassila/islands/GUIs/VisitGUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.aleksilassila.islands.GUIs;

import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.StaticPane;
import me.aleksilassila.islands.IslandsConfig;
import me.aleksilassila.islands.utils.BiomeMaterials;
Expand All @@ -24,8 +24,8 @@ public VisitGUI(Player player) {
}

@Override
public ChestGui getMainGui() {
ChestGui gui = createPaginatedGUI(PAGE_HEIGHT, Messages.get("gui.visit.TITLE"), getPanes());
public Gui getMainGui() {
Gui gui = createPaginatedGUI(PAGE_HEIGHT, Messages.get("gui.visit.TITLE"), getPanes());

StaticPane sort = new StaticPane(4, PAGE_HEIGHT - 1, 1, 1);

Expand Down
84 changes: 51 additions & 33 deletions src/me/aleksilassila/islands/protection/ProtectionListeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
Expand All @@ -25,22 +27,22 @@ public ProtectionListeners() {

@EventHandler
private void onEntityDamageEvent(EntityDamageByEntityEvent event) {
if (event.isCancelled()) return;
if (event.getEntity().getWorld().equals(Islands.islandsWorld) && event.getDamager() instanceof Player) {
if (event.getDamager().hasPermission(Permissions.bypass.interactEverywhere)) return;
if (event.isCancelled() || !event.getEntity().getWorld().equals(Islands.islandsWorld)) return;

int x = event.getEntity().getLocation().getBlockX();
int z = event.getEntity().getLocation().getBlockZ();
Player player;

String ownerUUID = IslandsConfig.getBlockOwnerUUID(x, z, event.getDamager().hasPermission(Permissions.bypass.interactInPlot));
if (ownerUUID != null && !ownerUUID.equals(event.getDamager().getUniqueId().toString())) {
if (new ProtectedBlock(x, z).canDoAnything(event.getDamager().getUniqueId().toString())) {
return;
}
if (event.getDamager() instanceof Player) player = (Player) event.getDamager();
else if (event.getDamager() instanceof Arrow) {
Arrow arrow = (Arrow) event.getDamager();

event.setCancelled(true);
event.getDamager().sendMessage(Messages.get("error.NOT_TRUSTED"));
}
if (arrow.getShooter() instanceof Player) player = (Player) arrow.getShooter();
else return;
} else return;

if (!canBuild(player, event.getEntity().getLocation().getBlockX(),
event.getEntity().getLocation().getBlockZ())) {
event.setCancelled(true);
player.sendMessage(Messages.get("error.NOT_TRUSTED"));
}
}

Expand Down Expand Up @@ -85,15 +87,8 @@ private void onPlayerBucketFill(PlayerBucketFillEvent event) {
private void onPlayerBucketEvent(PlayerBucketEvent event) {
if (event.isCancelled()) return;
if (event.getPlayer().getWorld().equals(Islands.islandsWorld)) {
if (event.getPlayer().hasPermission(Permissions.bypass.interactEverywhere)) return;

int x = event.getBlock().getLocation().getBlockX();
int z = event.getBlock().getLocation().getBlockZ();

String ownerUUID = IslandsConfig.getBlockOwnerUUID(x, z, event.getPlayer().hasPermission(Permissions.bypass.interactInPlot));
if (ownerUUID != null && !ownerUUID.equals(event.getPlayer().getUniqueId().toString())) {
if (new ProtectedBlock(x, z).canDoAnything(event.getPlayer().getUniqueId().toString())) return;

if (!canBuild(event.getPlayer(), event.getBlock().getLocation().getBlockX(),
event.getBlock().getLocation().getBlockZ())) {
event.setCancelled(true);
event.getPlayer().sendMessage(Messages.get("error.NOT_TRUSTED"));
}
Expand Down Expand Up @@ -134,7 +129,8 @@ private void onPlayerInteract(PlayerInteractEvent event) {
// These need permission to do anything
if (clickedBlock.getType() == Material.TNT ||
Tag.RAILS.isTagged(clickedBlock.getType()) ||
(event.getItem() != null && event.getItem().getType() == Material.BONE_MEAL)) {
(event.getItem() != null && event.getItem().getType() == Material.BONE_MEAL) ||
(event.getItem() != null && event.getItem().getType() == Material.ARMOR_STAND)) {
event.setCancelled(true);
Messages.send(event.getPlayer(), "error.NOT_TRUSTED");
return;
Expand Down Expand Up @@ -241,24 +237,46 @@ private void onBlockPlace(BlockPlaceEvent event) {

// MINECARTS
@EventHandler
private void on(VehicleDestroyEvent event) {
private void onVehicleDestroy(VehicleDestroyEvent event) {
if (event.isCancelled()) return;
if (!(event.getAttacker() instanceof Player)) return;

Player player = (Player) event.getAttacker();
if (player.getWorld().equals(Islands.islandsWorld)) {
if (player.hasPermission(Permissions.bypass.interactEverywhere)) return;

int x = event.getVehicle().getLocation().getBlockX();
int z = event.getVehicle().getLocation().getBlockZ();

String ownerUUID = IslandsConfig.getBlockOwnerUUID(x, z, player.hasPermission(Permissions.bypass.interactInPlot));
if (ownerUUID != null && !ownerUUID.equals(player.getUniqueId().toString())) {
if (new ProtectedBlock(x, z).canDoAnything(player.getUniqueId().toString())) return;
if (event.getVehicle().getWorld().equals(Islands.islandsWorld)) {
if (!canBuild(player, event.getVehicle().getLocation().getBlockX(),
event.getVehicle().getLocation().getBlockZ())) {

event.setCancelled(true);
player.sendMessage(Messages.get("error.NOT_TRUSTED"));
}
}
}

// ARROWS AND TNT IGNITION
@EventHandler
private void onEntityChangeBlock(EntityChangeBlockEvent event) {
if (event.isCancelled() || !Islands.islandsWorld.equals(event.getBlock().getWorld())) return;

if (event.getEntity() instanceof Arrow &&
event.getBlock().getType() == Material.TNT) {
Arrow arrow = (Arrow) event.getEntity();
if (arrow.getShooter() instanceof Player) {
Player owner = (Player) arrow.getShooter();

if (!canBuild(owner, event.getBlock().getX(), event.getBlock().getZ())) event.setCancelled(true);
}
}
}

public boolean canBuild(Player player, int x, int z) {
if (player.hasPermission(Permissions.bypass.interactEverywhere)) return true;

String ownerUUID = IslandsConfig.getBlockOwnerUUID(x, z, player.hasPermission(Permissions.bypass.interactInPlot));
if (ownerUUID == null) return false;
if (!ownerUUID.equals(player.getUniqueId().toString())) {
return new ProtectedBlock(x, z).canDoAnything(player.getUniqueId().toString());
}

return true;
}
}

0 comments on commit fd7a015

Please sign in to comment.