mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-10-31 23:59:35 +01:00
Faster
This commit is contained in:
parent
6ac0814358
commit
c0880b0a8c
5
pom.xml
5
pom.xml
@ -74,5 +74,10 @@
|
|||||||
<version>1.7.1</version>
|
<version>1.7.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.songoda</groupId>
|
||||||
|
<artifactId>epicspawners</artifactId>
|
||||||
|
<version>6-pre4</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -3,7 +3,7 @@ package com.songoda.epicanchors;
|
|||||||
import com.songoda.epicanchors.anchor.Anchor;
|
import com.songoda.epicanchors.anchor.Anchor;
|
||||||
import com.songoda.epicanchors.anchor.AnchorManager;
|
import com.songoda.epicanchors.anchor.AnchorManager;
|
||||||
import com.songoda.epicanchors.command.CommandManager;
|
import com.songoda.epicanchors.command.CommandManager;
|
||||||
import com.songoda.epicanchors.handlers.AnchorHandler;
|
import com.songoda.epicanchors.tasks.AnchorTask;
|
||||||
import com.songoda.epicanchors.listeners.BlockListeners;
|
import com.songoda.epicanchors.listeners.BlockListeners;
|
||||||
import com.songoda.epicanchors.listeners.InteractListeners;
|
import com.songoda.epicanchors.listeners.InteractListeners;
|
||||||
import com.songoda.epicanchors.utils.*;
|
import com.songoda.epicanchors.utils.*;
|
||||||
@ -75,7 +75,8 @@ public class EpicAnchors extends JavaPlugin {
|
|||||||
|
|
||||||
loadAnchorsFromFile();
|
loadAnchorsFromFile();
|
||||||
|
|
||||||
new AnchorHandler(this);
|
// Start tasks
|
||||||
|
new AnchorTask(this);
|
||||||
|
|
||||||
// Command registration
|
// Command registration
|
||||||
this.getCommand("EpicAnchors").setExecutor(new CommandManager(this));
|
this.getCommand("EpicAnchors").setExecutor(new CommandManager(this));
|
||||||
@ -148,7 +149,7 @@ public class EpicAnchors extends JavaPlugin {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack makeAnchorItem(int ticks) {
|
public ItemStack makAnchorItem(int ticks) {
|
||||||
ItemStack item = new ItemStack(Material.valueOf(EpicAnchors.getInstance().getConfig().getString("Main.Anchor Block Material")), 1);
|
ItemStack item = new ItemStack(Material.valueOf(EpicAnchors.getInstance().getConfig().getString("Main.Anchor Block Material")), 1);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(Methods.formatText(Methods.formatName(ticks, true)));
|
meta.setDisplayName(Methods.formatText(Methods.formatName(ticks, true)));
|
||||||
@ -162,26 +163,6 @@ public class EpicAnchors extends JavaPlugin {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bust(Location location) {
|
|
||||||
if (!getAnchorManager().isAnchor(location)) return;
|
|
||||||
|
|
||||||
Anchor anchor = getAnchorManager().getAnchor(location);
|
|
||||||
|
|
||||||
if (getConfig().getBoolean("Main.Allow Anchor Breaking")) {
|
|
||||||
ItemStack item = makeAnchorItem(anchor.getTicksLeft());
|
|
||||||
anchor.getLocation().getWorld().dropItemNaturally(anchor.getLocation(), item);
|
|
||||||
}
|
|
||||||
location.getBlock().setType(Material.AIR);
|
|
||||||
|
|
||||||
if (isServerVersionAtLeast(ServerVersion.V1_9))
|
|
||||||
location.getWorld().spawnParticle(Particle.LAVA, location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
|
||||||
|
|
||||||
location.getWorld().playSound(location, this.isServerVersionAtLeast(ServerVersion.V1_9)
|
|
||||||
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE"), 10, 10);
|
|
||||||
|
|
||||||
getAnchorManager().removeAnchor(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerVersion getServerVersion() {
|
public ServerVersion getServerVersion() {
|
||||||
return serverVersion;
|
return serverVersion;
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
package com.songoda.epicanchors.anchor;
|
package com.songoda.epicanchors.anchor;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchors;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
|
||||||
import com.songoda.epicanchors.gui.GUIOverview;
|
import com.songoda.epicanchors.gui.GUIOverview;
|
||||||
import com.songoda.epicanchors.utils.ServerVersion;
|
import com.songoda.epicanchors.utils.ServerVersion;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Particle;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
public class EAnchor implements Anchor {
|
public class Anchor {
|
||||||
|
|
||||||
private Location location;
|
private Location location;
|
||||||
private int ticksLeft;
|
private int ticksLeft;
|
||||||
|
|
||||||
public EAnchor(Location location, int ticksLeft) {
|
public Anchor(Location location, int ticksLeft) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.ticksLeft = ticksLeft;
|
this.ticksLeft = ticksLeft;
|
||||||
}
|
}
|
||||||
@ -64,17 +61,32 @@ public class EAnchor implements Anchor {
|
|||||||
player.getWorld().spawnParticle(Particle.SPELL_WITCH, getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
player.getWorld().spawnParticle(Particle.SPELL_WITCH, getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void bust() {
|
||||||
|
EpicAnchors plugin = EpicAnchors.getInstance();
|
||||||
|
|
||||||
|
if (plugin.getConfig().getBoolean("Main.Allow Anchor Breaking")) {
|
||||||
|
ItemStack item = plugin.makAnchorItem(getTicksLeft());
|
||||||
|
getLocation().getWorld().dropItemNaturally(getLocation(), item);
|
||||||
|
}
|
||||||
|
location.getBlock().setType(Material.AIR);
|
||||||
|
|
||||||
|
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||||
|
location.getWorld().spawnParticle(Particle.LAVA, location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
||||||
|
|
||||||
|
location.getWorld().playSound(location, plugin.isServerVersionAtLeast(ServerVersion.V1_9)
|
||||||
|
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE"), 10, 10);
|
||||||
|
|
||||||
|
plugin.getAnchorManager().removAnchor(location);
|
||||||
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return location.clone();
|
return location.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTicksLeft() {
|
public int getTicksLeft() {
|
||||||
return ticksLeft;
|
return ticksLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTicksLeft(int ticksLeft) {
|
public void setTicksLeft(int ticksLeft) {
|
||||||
this.ticksLeft = ticksLeft;
|
this.ticksLeft = ticksLeft;
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,31 @@
|
|||||||
package com.songoda.epicanchors.anchor;
|
package com.songoda.epicanchors.anchor;
|
||||||
|
|
||||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
|
||||||
import com.songoda.epicanchors.api.anchor.AnchorManager;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class EAnchorManager implements AnchorManager {
|
public class AnchorManager {
|
||||||
|
|
||||||
private final Map<Location, Anchor> registeredAnchors = new HashMap<>();
|
private final Map<Location, Anchor> registeredAnchors = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
|
||||||
public Anchor addAnchor(Location location, Anchor anchor) {
|
public Anchor addAnchor(Location location, Anchor anchor) {
|
||||||
return registeredAnchors.put(roundLocation(location), anchor);
|
return registeredAnchors.put(roundLocation(location), anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void removAnchor(Location location) {
|
||||||
public void removeAnchor(Location location) {
|
|
||||||
registeredAnchors.remove(roundLocation(location));
|
registeredAnchors.remove(roundLocation(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Anchor getAnchor(Location location) {
|
public Anchor getAnchor(Location location) {
|
||||||
return registeredAnchors.get(roundLocation(location));
|
return registeredAnchors.get(roundLocation(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnchor(Location location) {
|
public boolean isAnchor(Location location) {
|
||||||
return registeredAnchors.containsKey(location);
|
return registeredAnchors.containsKey(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<Location, Anchor> getAnchors() {
|
public Map<Location, Anchor> getAnchors() {
|
||||||
return Collections.unmodifiableMap(registeredAnchors);
|
return Collections.unmodifiableMap(registeredAnchors);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.command;
|
package com.songoda.epicanchors.command;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public abstract class AbstractCommand {
|
public abstract class AbstractCommand {
|
||||||
@ -31,7 +31,7 @@ public abstract class AbstractCommand {
|
|||||||
return noConsole;
|
return noConsole;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args);
|
protected abstract ReturnType runCommand(EpicAnchors instance, CommandSender sender, String... args);
|
||||||
|
|
||||||
public abstract String getPermissionNode();
|
public abstract String getPermissionNode();
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.command;
|
package com.songoda.epicanchors.command;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.command.commands.CommandEpicAnchors;
|
import com.songoda.epicanchors.command.commands.CommandEpicAnchors;
|
||||||
import com.songoda.epicanchors.command.commands.CommandGive;
|
import com.songoda.epicanchors.command.commands.CommandGive;
|
||||||
import com.songoda.epicanchors.command.commands.CommandReload;
|
import com.songoda.epicanchors.command.commands.CommandReload;
|
||||||
@ -17,11 +17,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CommandManager implements CommandExecutor {
|
public class CommandManager implements CommandExecutor {
|
||||||
|
|
||||||
private EpicAnchorsPlugin instance;
|
private EpicAnchors instance;
|
||||||
|
|
||||||
private List<AbstractCommand> commands = new ArrayList<>();
|
private List<AbstractCommand> commands = new ArrayList<>();
|
||||||
|
|
||||||
public CommandManager(EpicAnchorsPlugin instance) {
|
public CommandManager(EpicAnchors instance) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
|
|
||||||
AbstractCommand commandEpicAnchors = addCommand(new CommandEpicAnchors());
|
AbstractCommand commandEpicAnchors = addCommand(new CommandEpicAnchors());
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.command.commands;
|
package com.songoda.epicanchors.command.commands;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.command.AbstractCommand;
|
import com.songoda.epicanchors.command.AbstractCommand;
|
||||||
import com.songoda.epicanchors.utils.Methods;
|
import com.songoda.epicanchors.utils.Methods;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -12,7 +12,7 @@ public class CommandEpicAnchors extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
protected ReturnType runCommand(EpicAnchors instance, CommandSender sender, String... args) {
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.command.commands;
|
package com.songoda.epicanchors.command.commands;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.command.AbstractCommand;
|
import com.songoda.epicanchors.command.AbstractCommand;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -14,7 +14,7 @@ public class CommandGive extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
protected ReturnType runCommand(EpicAnchors instance, CommandSender sender, String... args) {
|
||||||
if (args.length != 3) return ReturnType.SYNTAX_ERROR;
|
if (args.length != 3) return ReturnType.SYNTAX_ERROR;
|
||||||
|
|
||||||
if (Bukkit.getPlayer(args[1]) == null && !args[1].trim().toLowerCase().equals("all")) {
|
if (Bukkit.getPlayer(args[1]) == null && !args[1].trim().toLowerCase().equals("all")) {
|
||||||
@ -22,7 +22,7 @@ public class CommandGive extends AbstractCommand {
|
|||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack itemStack = instance.makeAnchorItem(Integer.parseInt(args[2]) * 20 * 60 * 60);
|
ItemStack itemStack = instance.makAnchorItem(Integer.parseInt(args[2]) * 20 * 60 * 60);
|
||||||
|
|
||||||
if (!args[1].trim().toLowerCase().equals("all")) {
|
if (!args[1].trim().toLowerCase().equals("all")) {
|
||||||
Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer();
|
Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.command.commands;
|
package com.songoda.epicanchors.command.commands;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.command.AbstractCommand;
|
import com.songoda.epicanchors.command.AbstractCommand;
|
||||||
import com.songoda.epicanchors.utils.Methods;
|
import com.songoda.epicanchors.utils.Methods;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -12,7 +12,7 @@ public class CommandReload extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
protected ReturnType runCommand(EpicAnchors instance, CommandSender sender, String... args) {
|
||||||
instance.reload();
|
instance.reload();
|
||||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.command.commands;
|
package com.songoda.epicanchors.command.commands;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.command.AbstractCommand;
|
import com.songoda.epicanchors.command.AbstractCommand;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -12,7 +12,7 @@ public class CommandSettings extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
protected ReturnType runCommand(EpicAnchors instance, CommandSender sender, String... args) {
|
||||||
instance.getSettingsManager().openSettingsManager((Player) sender);
|
instance.getSettingsManager().openSettingsManager((Player) sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.songoda.epicanchors.gui;
|
package com.songoda.epicanchors.gui;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.anchor.EAnchor;
|
import com.songoda.epicanchors.anchor.Anchor;
|
||||||
import com.songoda.epicanchors.utils.Methods;
|
import com.songoda.epicanchors.utils.Methods;
|
||||||
import com.songoda.epicanchors.utils.gui.AbstractGUI;
|
import com.songoda.epicanchors.utils.gui.AbstractGUI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -15,12 +15,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public class GUIOverview extends AbstractGUI {
|
public class GUIOverview extends AbstractGUI {
|
||||||
|
|
||||||
private final EpicAnchorsPlugin plugin;
|
private final EpicAnchors plugin;
|
||||||
private final EAnchor anchor;
|
private final Anchor anchor;
|
||||||
|
|
||||||
private int task;
|
private int task;
|
||||||
|
|
||||||
public GUIOverview(EpicAnchorsPlugin plugin, EAnchor anchor, Player player) {
|
public GUIOverview(EpicAnchors plugin, Anchor anchor, Player player) {
|
||||||
super(player);
|
super(player);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.anchor = anchor;
|
this.anchor = anchor;
|
||||||
@ -72,7 +72,7 @@ public class GUIOverview extends AbstractGUI {
|
|||||||
itemmetaECO.setLore(loreECO);
|
itemmetaECO.setLore(loreECO);
|
||||||
itemECO.setItemMeta(itemmetaECO);
|
itemECO.setItemMeta(itemmetaECO);
|
||||||
|
|
||||||
ItemStack item = plugin.makeAnchorItem(anchor.getTicksLeft());
|
ItemStack item = plugin.makAnchorItem(anchor.getTicksLeft());
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(Methods.formatText(plugin.getLocale().getMessage("interface.anchor.smalltitle")));
|
meta.setDisplayName(Methods.formatText(plugin.getLocale().getMessage("interface.anchor.smalltitle")));
|
||||||
List<String> lore = new ArrayList<>();
|
List<String> lore = new ArrayList<>();
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package com.songoda.epicanchors.listeners;
|
package com.songoda.epicanchors.listeners;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.anchor.EAnchor;
|
import com.songoda.epicanchors.anchor.Anchor;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
@ -13,20 +10,14 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
public class BlockListeners implements Listener {
|
public class BlockListeners implements Listener {
|
||||||
|
|
||||||
private EpicAnchorsPlugin instance;
|
private EpicAnchors instance;
|
||||||
|
|
||||||
public BlockListeners(EpicAnchorsPlugin instance) {
|
public BlockListeners(EpicAnchors instance) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
Player player = event.getPlayer();
|
|
||||||
Block block = event.getBlock();
|
|
||||||
|
|
||||||
if (!instance.canBuild(player, block.getLocation())
|
|
||||||
|| event.getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Anchor Block Material")))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ItemStack item = event.getItemInHand();
|
ItemStack item = event.getItemInHand();
|
||||||
|
|
||||||
@ -34,7 +25,7 @@ public class BlockListeners implements Listener {
|
|||||||
|| !item.getItemMeta().hasDisplayName()
|
|| !item.getItemMeta().hasDisplayName()
|
||||||
|| instance.getTicksFromItem(item) == 0) return;
|
|| instance.getTicksFromItem(item) == 0) return;
|
||||||
|
|
||||||
instance.getAnchorManager().addAnchor(event.getBlock().getLocation(), new EAnchor(event.getBlock().getLocation(), instance.getTicksFromItem(item)));
|
instance.getAnchorManager().addAnchor(event.getBlock().getLocation(), new Anchor(event.getBlock().getLocation(), instance.getTicksFromItem(item)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.songoda.epicanchors.listeners;
|
package com.songoda.epicanchors.listeners;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.anchor.EAnchor;
|
import com.songoda.epicanchors.anchor.Anchor;
|
||||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
|
||||||
import com.songoda.epicanchors.utils.Methods;
|
import com.songoda.epicanchors.utils.Methods;
|
||||||
import com.songoda.epicanchors.utils.ServerVersion;
|
import com.songoda.epicanchors.utils.ServerVersion;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -18,9 +17,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
public class InteractListeners implements Listener {
|
public class InteractListeners implements Listener {
|
||||||
|
|
||||||
private EpicAnchorsPlugin instance;
|
private EpicAnchors instance;
|
||||||
|
|
||||||
public InteractListeners(EpicAnchorsPlugin instance) {
|
public InteractListeners(EpicAnchors instance) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,22 +28,15 @@ public class InteractListeners implements Listener {
|
|||||||
public void onBlockInteract(PlayerInteractEvent event) {
|
public void onBlockInteract(PlayerInteractEvent event) {
|
||||||
if (event.getClickedBlock() == null) return;
|
if (event.getClickedBlock() == null) return;
|
||||||
|
|
||||||
if (instance.getAnchorManager().getAnchor(event.getClickedBlock().getLocation()) == null) return;
|
|
||||||
|
|
||||||
if (!instance.canBuild(event.getPlayer(), event.getClickedBlock().getLocation())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
|
||||||
instance.bust(event.getClickedBlock().getLocation());
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Anchor anchor = instance.getAnchorManager().getAnchor(event.getClickedBlock().getLocation());
|
Anchor anchor = instance.getAnchorManager().getAnchor(event.getClickedBlock().getLocation());
|
||||||
|
|
||||||
|
if (anchor == null) return;
|
||||||
|
|
||||||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
anchor.bust();
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ItemStack item = player.getItemInHand();
|
ItemStack item = player.getItemInHand();
|
||||||
@ -63,10 +55,10 @@ public class InteractListeners implements Listener {
|
|||||||
if (player.getGameMode() != GameMode.CREATIVE)
|
if (player.getGameMode() != GameMode.CREATIVE)
|
||||||
Methods.takeItem(player, 1);
|
Methods.takeItem(player, 1);
|
||||||
|
|
||||||
Sound sound = EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP");
|
Sound sound = EpicAnchors.getInstance().isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP");
|
||||||
player.playSound(player.getLocation(), sound, 0.6F, 15.0F);
|
player.playSound(player.getLocation(), sound, 0.6F, 15.0F);
|
||||||
|
|
||||||
if (EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9))
|
if (EpicAnchors.getInstance().isServerVersionAtLeast(ServerVersion.V1_9))
|
||||||
player.getWorld().spawnParticle(Particle.SPELL_WITCH, anchor.getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
player.getWorld().spawnParticle(Particle.SPELL_WITCH, anchor.getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -74,7 +66,7 @@ public class InteractListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((EAnchor) anchor).overview(player);
|
((Anchor) anchor).overview(player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,29 +1,25 @@
|
|||||||
package com.songoda.epicanchors.handlers;
|
package com.songoda.epicanchors.tasks;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
import com.songoda.epicanchors.anchor.Anchor;
|
||||||
import com.songoda.epicanchors.utils.ServerVersion;
|
import com.songoda.epicanchors.utils.ServerVersion;
|
||||||
import com.songoda.epicspawners.EpicSpawners;
|
import com.songoda.epicspawners.EpicSpawners;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Particle;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class AnchorHandler {
|
public class AnchorTask extends BukkitRunnable {
|
||||||
|
|
||||||
|
private static EpicAnchors plugin;
|
||||||
|
|
||||||
private EpicAnchorsPlugin instance;
|
|
||||||
private Map<Location, Integer> delays = new HashMap<>();
|
private Map<Location, Integer> delays = new HashMap<>();
|
||||||
|
|
||||||
private Class<?> clazzEntity, clazzCraftEntity, clazzMinecraftServer;
|
private Class<?> clazzEntity, clazzCraftEntity, clazzMinecraftServer;
|
||||||
@ -34,22 +30,24 @@ public class AnchorHandler {
|
|||||||
|
|
||||||
private boolean epicSpawners;
|
private boolean epicSpawners;
|
||||||
|
|
||||||
public AnchorHandler(EpicAnchorsPlugin instance) {
|
|
||||||
this.instance = instance;
|
|
||||||
|
|
||||||
|
public AnchorTask(EpicAnchors plug) {
|
||||||
|
plugin = plug;
|
||||||
|
epicSpawners = Bukkit.getPluginManager().getPlugin("EpicSpawners") != null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
||||||
clazzMinecraftServer = Class.forName("net.minecraft.server." + ver + ".MinecraftServer");
|
clazzMinecraftServer = Class.forName("net.minecraft.server." + ver + ".MinecraftServer");
|
||||||
clazzEntity = Class.forName("net.minecraft.server." + ver + ".Entity");
|
clazzEntity = Class.forName("net.minecraft.server." + ver + ".Entity");
|
||||||
clazzCraftEntity = Class.forName("org.bukkit.craftbukkit." + ver + ".entity.CraftEntity");
|
clazzCraftEntity = Class.forName("org.bukkit.craftbukkit." + ver + ".entity.CraftEntity");
|
||||||
|
|
||||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_13))
|
if (plugin.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||||
methodTick = clazzEntity.getDeclaredMethod("tick");
|
methodTick = clazzEntity.getDeclaredMethod("tick");
|
||||||
else if (instance.isServerVersion(ServerVersion.V1_12))
|
else if (plugin.isServerVersion(ServerVersion.V1_12))
|
||||||
methodTick = clazzEntity.getDeclaredMethod("B_");
|
methodTick = clazzEntity.getDeclaredMethod("B_");
|
||||||
else if (instance.isServerVersion(ServerVersion.V1_11))
|
else if (plugin.isServerVersion(ServerVersion.V1_11))
|
||||||
methodTick = clazzEntity.getDeclaredMethod("A_");
|
methodTick = clazzEntity.getDeclaredMethod("A_");
|
||||||
else if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
|
else if (plugin.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||||
methodTick = clazzEntity.getDeclaredMethod("m");
|
methodTick = clazzEntity.getDeclaredMethod("m");
|
||||||
else
|
else
|
||||||
methodTick = clazzEntity.getDeclaredMethod("t_");
|
methodTick = clazzEntity.getDeclaredMethod("t_");
|
||||||
@ -62,15 +60,12 @@ public class AnchorHandler {
|
|||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
epicSpawners = instance.getServer().getPluginManager().getPlugin("EpicSpawners") != null;
|
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::doAnchorCheck, 0, 1); //ToDo: way to fast.
|
this.runTaskTimer(plugin, 0, 3);
|
||||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
|
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::doParticle, 0, 2); //ToDo: way to fast.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doParticle() {
|
private void doParticle() {
|
||||||
for (Anchor anchor : instance.getAnchorManager().getAnchors().values()) {
|
for (Anchor anchor : plugin.getAnchorManager().getAnchors().values()) {
|
||||||
Location location1 = anchor.getLocation().add(.5, .5, .5);
|
Location location1 = anchor.getLocation().add(.5, .5, .5);
|
||||||
if (location1.getWorld() == null) continue;
|
if (location1.getWorld() == null) continue;
|
||||||
float xx = (float) (0 + (Math.random() * .15));
|
float xx = (float) (0 + (Math.random() * .15));
|
||||||
@ -81,23 +76,24 @@ public class AnchorHandler {
|
|||||||
xx = (float) (0 + (Math.random() * .75));
|
xx = (float) (0 + (Math.random() * .75));
|
||||||
yy = (float) (0 + (Math.random() * 1));
|
yy = (float) (0 + (Math.random() * 1));
|
||||||
zz = (float) (0 + (Math.random() * .75));
|
zz = (float) (0 + (Math.random() * .75));
|
||||||
if (!instance.isServerVersionAtLeast(ServerVersion.V1_13))
|
if (!plugin.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||||
location1.getWorld().spawnParticle(Particle.REDSTONE, location1, 5, xx, yy, zz, 1);
|
location1.getWorld().spawnParticle(Particle.REDSTONE, location1, 5, xx, yy, zz, 1);
|
||||||
else
|
else
|
||||||
location1.getWorld().spawnParticle(Particle.REDSTONE, location1, 5, xx, yy, zz, 1, new Particle.DustOptions(Color.WHITE, 1F));
|
location1.getWorld().spawnParticle(Particle.REDSTONE, location1, 5, xx, yy, zz, 1, new Particle.DustOptions(Color.WHITE, 1F));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doAnchorCheck() {
|
@Override
|
||||||
for (Anchor anchor : instance.getAnchorManager().getAnchors().values()) {
|
public void run() {
|
||||||
|
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||||
|
doParticle();
|
||||||
|
for (Anchor anchor : plugin.getAnchorManager().getAnchors().values()) {
|
||||||
|
|
||||||
if (anchor.getLocation() == null) continue;
|
if (anchor.getLocation() == null) continue;
|
||||||
|
|
||||||
Location location = anchor.getLocation();
|
Location location = anchor.getLocation();
|
||||||
|
|
||||||
if (anchor.getLocation().getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Anchor Block Material")))
|
if (anchor.getLocation().getBlock().getType() != Material.valueOf(plugin.getConfig().getString("Main.Anchor Block Material")))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Chunk chunk = location.getChunk();
|
Chunk chunk = location.getChunk();
|
||||||
@ -123,13 +119,13 @@ public class AnchorHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ticksLeft = anchor.getTicksLeft();
|
int ticksLeft = anchor.getTicksLeft();
|
||||||
anchor.setTicksLeft(ticksLeft - 1);
|
anchor.setTicksLeft(ticksLeft - 3);
|
||||||
|
|
||||||
if (ticksLeft <= 0) {
|
if (ticksLeft <= 0) {
|
||||||
instance.getAnchorManager().removeAnchor(location);
|
plugin.getAnchorManager().removAnchor(location);
|
||||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
|
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||||
location.getWorld().spawnParticle(Particle.LAVA, location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
location.getWorld().spawnParticle(Particle.LAVA, location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
||||||
location.getWorld().playSound(location, instance.isServerVersionAtLeast(ServerVersion.V1_13)
|
location.getWorld().playSound(location, plugin.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||||
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE"), 10, 10);
|
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE"), 10, 10);
|
||||||
location.getBlock().setType(Material.AIR);
|
location.getBlock().setType(Material.AIR);
|
||||||
chunk.unload();
|
chunk.unload();
|
@ -173,7 +173,7 @@ public class SettingsManager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Setting {
|
public enum Setting {
|
||||||
o1("Main.Name-Tag", "&eAnchor &8(&7{REMAINING}&8)"),
|
o1("Main.Name-Tag", "&Anchor &8(&7{REMAINING}&8)"),
|
||||||
o2("Main.Anchor-Lore", "&7Place down to keep that chunk|&7loaded until the time runs out."),
|
o2("Main.Anchor-Lore", "&7Place down to keep that chunk|&7loaded until the time runs out."),
|
||||||
o3("Main.Anchor Block Material", EpicAnchors.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "END_PORTAL_FRAME" : "ENDER_PORTAL_FRAME"),
|
o3("Main.Anchor Block Material", EpicAnchors.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "END_PORTAL_FRAME" : "ENDER_PORTAL_FRAME"),
|
||||||
o4("Main.Add Time With Economy", true),
|
o4("Main.Add Time With Economy", true),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.utils.gui;
|
package com.songoda.epicanchors.utils.gui;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.utils.Methods;
|
import com.songoda.epicanchors.utils.Methods;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -125,7 +125,7 @@ public abstract class AbstractGUI implements Listener {
|
|||||||
registerOnCloses();
|
registerOnCloses();
|
||||||
}
|
}
|
||||||
constructGUI();
|
constructGUI();
|
||||||
initializeListeners(EpicAnchorsPlugin.getInstance());
|
initializeListeners(EpicAnchors.getInstance());
|
||||||
player.openInventory(inventory);
|
player.openInventory(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.songoda.epicanchors.utils.gui;
|
package com.songoda.epicanchors.utils.gui;
|
||||||
|
|
||||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
import com.songoda.epicanchors.utils.ServerVersion;
|
import com.songoda.epicanchors.utils.ServerVersion;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
@ -24,7 +24,7 @@ public class Range {
|
|||||||
this.bottom = bottom;
|
this.bottom = bottom;
|
||||||
|
|
||||||
if (onClickSound == null) {
|
if (onClickSound == null) {
|
||||||
if (EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) {
|
if (EpicAnchors.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||||
this.onClickSound = Sound.UI_BUTTON_CLICK;
|
this.onClickSound = Sound.UI_BUTTON_CLICK;
|
||||||
} else {
|
} else {
|
||||||
this.onClickSound = Sound.valueOf("CLICK");
|
this.onClickSound = Sound.valueOf("CLICK");
|
||||||
|
@ -2,7 +2,7 @@ name: EpicAnchors
|
|||||||
description: EpicAnchors
|
description: EpicAnchors
|
||||||
version: maven-version-number
|
version: maven-version-number
|
||||||
softdepend: [EpicSpawners, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault]
|
softdepend: [EpicSpawners, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault]
|
||||||
main: com.songoda.epicanchors.EpicAnchorsPlugin
|
main: com.songoda.epicanchors.EpicAnchors
|
||||||
author: songoda
|
author: songoda
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
commands:
|
commands:
|
||||||
|
Loading…
Reference in New Issue
Block a user