mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-11-22 18:15:53 +01:00
Added infinite anchors
This commit is contained in:
parent
650995d14a
commit
94faccbc41
@ -11,6 +11,7 @@ public class Anchor {
|
|||||||
|
|
||||||
private Location location;
|
private Location location;
|
||||||
private int ticksLeft;
|
private int ticksLeft;
|
||||||
|
private boolean isInfinite;
|
||||||
|
|
||||||
private final int chunkX;
|
private final int chunkX;
|
||||||
private final int chunkZ;
|
private final int chunkZ;
|
||||||
@ -20,6 +21,7 @@ public class Anchor {
|
|||||||
this.chunkX = location.getBlockX() >> 4;
|
this.chunkX = location.getBlockX() >> 4;
|
||||||
this.chunkZ = location.getBlockZ() >> 4;
|
this.chunkZ = location.getBlockZ() >> 4;
|
||||||
this.ticksLeft = ticksLeft;
|
this.ticksLeft = ticksLeft;
|
||||||
|
this.isInfinite = (ticksLeft == -99);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTime(String type, Player player) {
|
public void addTime(String type, Player player) {
|
||||||
@ -96,4 +98,12 @@ public class Anchor {
|
|||||||
public void setTicksLeft(int ticksLeft) {
|
public void setTicksLeft(int ticksLeft) {
|
||||||
this.ticksLeft = ticksLeft;
|
this.ticksLeft = ticksLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isInfinite() {
|
||||||
|
return isInfinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInfinite(boolean infinite) {
|
||||||
|
isInfinite = infinite;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.songoda.epicanchors.commands;
|
|||||||
|
|
||||||
import com.songoda.core.commands.AbstractCommand;
|
import com.songoda.core.commands.AbstractCommand;
|
||||||
import com.songoda.epicanchors.EpicAnchors;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
|
import com.songoda.epicanchors.utils.Methods;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -31,16 +32,19 @@ public class CommandGive extends AbstractCommand {
|
|||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
Integer.parseInt(args[1]);
|
|
||||||
} catch (Exception e) {
|
ItemStack itemStack;
|
||||||
|
|
||||||
|
if (Methods.isInt(args[1])) {
|
||||||
|
itemStack = (Integer.parseInt(args[1]) <= 0) ? instance.makeAnchorItem(-99) : instance.makeAnchorItem(Integer.parseInt(args[1]) * 20 * 60 * 60);
|
||||||
|
} else if (args[1].toLowerCase().equals("infinite")) {
|
||||||
|
itemStack = instance.makeAnchorItem(-99);
|
||||||
|
} else {
|
||||||
instance.getLocale().newMessage("&cYou can only use whole numbers...").sendPrefixedMessage(sender);
|
instance.getLocale().newMessage("&cYou can only use whole numbers...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ItemStack itemStack = instance.makeAnchorItem(Integer.parseInt(args[1]) * 20 * 60 * 60);
|
|
||||||
|
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
target.getInventory().addItem(itemStack);
|
target.getInventory().addItem(itemStack);
|
||||||
instance.getLocale().getMessage("command.give.success").sendPrefixedMessage(target);
|
instance.getLocale().getMessage("command.give.success").sendPrefixedMessage(target);
|
||||||
@ -50,6 +54,7 @@ public class CommandGive extends AbstractCommand {
|
|||||||
instance.getLocale().getMessage("command.give.success").sendPrefixedMessage(player);
|
instance.getLocale().getMessage("command.give.success").sendPrefixedMessage(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +80,7 @@ public class CommandGive extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSyntax() {
|
public String getSyntax() {
|
||||||
return "/ea give <player/all> <amount in hours>";
|
return "/ea give <player/all> <amount in hours / infinite>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,22 +49,22 @@ public class GUIOverview extends Gui {
|
|||||||
|
|
||||||
setItem(13, GuiUtils.createButtonItem(plugin.makeAnchorItem(anchor.getTicksLeft()),
|
setItem(13, GuiUtils.createButtonItem(plugin.makeAnchorItem(anchor.getTicksLeft()),
|
||||||
plugin.getLocale().getMessage("interface.anchor.smalltitle").getMessage(),
|
plugin.getLocale().getMessage("interface.anchor.smalltitle").getMessage(),
|
||||||
ChatColor.GRAY + Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining."));
|
(anchor.isInfinite()) ? ChatColor.GRAY + "Infinite" : ChatColor.GRAY + Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining."));
|
||||||
|
|
||||||
if (EconomyManager.isEnabled() && Settings.ADD_TIME_WITH_ECONOMY.getBoolean()) {
|
if (EconomyManager.isEnabled() && Settings.ADD_TIME_WITH_ECONOMY.getBoolean()) {
|
||||||
setButton(15, GuiUtils.createButtonItem(Settings.ECO_ICON.getMaterial(CompatibleMaterial.SUNFLOWER),
|
setButton(15, GuiUtils.createButtonItem(Settings.ECO_ICON.getMaterial(CompatibleMaterial.SUNFLOWER),
|
||||||
plugin.getLocale().getMessage("interface.button.addtimewitheconomy").getMessage(),
|
plugin.getLocale().getMessage("interface.button.addtimewitheconomy").getMessage(),
|
||||||
plugin.getLocale().getMessage("interface.button.addtimewitheconomylore")
|
plugin.getLocale().getMessage("interface.button.addtimewitheconomylore")
|
||||||
.processPlaceholder("cost", Methods.formatEconomy(Settings.ECONOMY_COST.getDouble())).getMessage()), // EconomyManager.formatEconomy adds its own prefix/suffix
|
.processPlaceholder("cost", Methods.formatEconomy(Settings.ECONOMY_COST.getDouble())).getMessage()), // EconomyManager.formatEconomy adds its own prefix/suffix
|
||||||
event -> anchor.addTime("ECO", event.player));
|
event -> checkInfiniteAndAlert(anchor, event.player, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.ADD_TIME_WITH_XP.getBoolean()) {
|
if (Settings.ADD_TIME_WITH_XP.getBoolean()) {
|
||||||
setButton(11, GuiUtils.createButtonItem(Settings.XP_ICON.getMaterial(CompatibleMaterial.EXPERIENCE_BOTTLE),
|
setButton(11, GuiUtils.createButtonItem(Settings.XP_ICON.getMaterial(CompatibleMaterial.EXPERIENCE_BOTTLE),
|
||||||
plugin.getLocale().getMessage("interface.button.addtimewithxp").getMessage(),
|
plugin.getLocale().getMessage("interface.button.addtimewithxp").getMessage(),
|
||||||
plugin.getLocale().getMessage("interface.button.addtimewithxplore")
|
plugin.getLocale().getMessage("interface.button.addtimewithxplore")
|
||||||
.processPlaceholder("cost", String.valueOf(Settings.XP_COST.getInt())).getMessage()),
|
.processPlaceholder("cost", String.valueOf(Settings.XP_COST.getInt())).getMessage()),
|
||||||
event -> anchor.addTime("XP", event.player));
|
event -> checkInfiniteAndAlert(anchor, event.player, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,7 +72,19 @@ public class GUIOverview extends Gui {
|
|||||||
private void runTask() {
|
private void runTask() {
|
||||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||||
updateItem(13, plugin.getLocale().getMessage("interface.anchor.smalltitle").getMessage(),
|
updateItem(13, plugin.getLocale().getMessage("interface.anchor.smalltitle").getMessage(),
|
||||||
ChatColor.GRAY + Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining.");
|
(anchor.isInfinite()) ? ChatColor.GRAY + "Infinite" : ChatColor.GRAY + Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining.");
|
||||||
}, 5L, 5L);
|
}, 5L, 5L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkInfiniteAndAlert(Anchor anchor, Player p, boolean eco) {
|
||||||
|
if (anchor.isInfinite()) {
|
||||||
|
plugin.getLocale().getMessage("interface.button.infinite").sendPrefixedMessage(p);
|
||||||
|
} else {
|
||||||
|
if (eco) {
|
||||||
|
anchor.addTime("ECO", p);
|
||||||
|
} else {
|
||||||
|
anchor.addTime("XP", p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,12 @@ public class BlockListeners implements Listener {
|
|||||||
|| plugin.getTicksFromItem(item) == 0) return;
|
|| plugin.getTicksFromItem(item) == 0) return;
|
||||||
|
|
||||||
Anchor anchor = new Anchor(event.getBlock().getLocation(), plugin.getTicksFromItem(item));
|
Anchor anchor = new Anchor(event.getBlock().getLocation(), plugin.getTicksFromItem(item));
|
||||||
plugin.getAnchorManager().addAnchor(event.getBlock().getLocation(), anchor);
|
|
||||||
|
|
||||||
|
if (plugin.getTicksFromItem(item) == -99) {
|
||||||
|
anchor.setInfinite(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getAnchorManager().addAnchor(event.getBlock().getLocation(), anchor);
|
||||||
plugin.updateHologram(anchor);
|
plugin.updateHologram(anchor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,9 +110,12 @@ public class AnchorTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ticksLeft = anchor.getTicksLeft();
|
int ticksLeft = anchor.getTicksLeft();
|
||||||
anchor.setTicksLeft(ticksLeft - 3);
|
|
||||||
|
|
||||||
if (ticksLeft <= 0) {
|
if (!anchor.isInfinite()) {
|
||||||
|
anchor.setTicksLeft(ticksLeft - 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ticksLeft <= 0 && !anchor.isInfinite()) {
|
||||||
anchor.bust();
|
anchor.bust();
|
||||||
chunk.unload();
|
chunk.unload();
|
||||||
return;
|
return;
|
||||||
|
@ -19,7 +19,7 @@ public class Methods {
|
|||||||
|
|
||||||
String remaining = Methods.makeReadable((ticks2 / 20L) * 1000L);
|
String remaining = Methods.makeReadable((ticks2 / 20L) * 1000L);
|
||||||
|
|
||||||
String name = Settings.NAMETAG.getString().replace("{REMAINING}", remaining);
|
String name = Settings.NAMETAG.getString().replace("{REMAINING}", (ticks2 <= 0) ? "Infinite" : remaining);
|
||||||
|
|
||||||
String info = "";
|
String info = "";
|
||||||
if (full) {
|
if (full) {
|
||||||
@ -156,6 +156,19 @@ public class Methods {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isInt(String number) {
|
||||||
|
if (number != null && !number.equals("")) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(number);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException var2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the specified double into the Economy format specified in the Arconix config.
|
* Formats the specified double into the Economy format specified in the Arconix config.
|
||||||
*
|
*
|
||||||
|
@ -14,6 +14,7 @@ interface:
|
|||||||
addtimewithxplore: '&7Cost: &a%cost% Levels'
|
addtimewithxplore: '&7Cost: &a%cost% Levels'
|
||||||
addtimewitheconomy: '&aAdd 30 Minutes with ECO'
|
addtimewitheconomy: '&aAdd 30 Minutes with ECO'
|
||||||
addtimewitheconomylore: '&7Cost: &a$%cost%'
|
addtimewitheconomylore: '&7Cost: &a$%cost%'
|
||||||
|
infinite: '&cCannot upgrade an infinite anchor!'
|
||||||
anchor:
|
anchor:
|
||||||
title: ChunkAnchor
|
title: ChunkAnchor
|
||||||
smalltitle: '&eChunkAnchor'
|
smalltitle: '&eChunkAnchor'
|
||||||
|
Loading…
Reference in New Issue
Block a user