mirror of
https://github.com/songoda/EpicHoppers.git
synced 2025-01-25 09:01:35 +01:00
Boost system.
This commit is contained in:
parent
d16df1b6a6
commit
19f7fcb373
@ -55,6 +55,13 @@ public interface Hopper {
|
||||
*/
|
||||
Level getLevel();
|
||||
|
||||
/**
|
||||
* Get the player that placed this hopper.
|
||||
*
|
||||
* @return the player the placed this hopper.
|
||||
*/
|
||||
UUID getPlacedBy();
|
||||
|
||||
/**
|
||||
* Get the player that last used this hopper.
|
||||
*
|
||||
|
@ -12,6 +12,8 @@ import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.LevelManager;
|
||||
import com.songoda.epichoppers.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epichoppers.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.boost.BoostManager;
|
||||
import com.songoda.epichoppers.command.CommandManager;
|
||||
import com.songoda.epichoppers.handlers.EnchantmentHandler;
|
||||
import com.songoda.epichoppers.handlers.HopHandler;
|
||||
@ -33,6 +35,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -64,6 +67,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
|
||||
private HopperManager hopperManager;
|
||||
private LevelManager levelManager;
|
||||
private BoostManager boostManager;
|
||||
private PlayerDataManager playerDataManager;
|
||||
|
||||
private TeleportHandler teleportHandler;
|
||||
@ -79,6 +83,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
settingsManager = new SettingsManager(this);
|
||||
boostManager = new BoostManager();
|
||||
setupConfig();
|
||||
loadDataFile();
|
||||
enchantmentHandler = new EnchantmentHandler();
|
||||
@ -110,7 +115,9 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
boolean walkOnTeleport = dataFile.getConfig().getBoolean("data.sync." + locationStr + ".walkOnTeleport");
|
||||
|
||||
String playerStr = dataFile.getConfig().getString("data.sync." + locationStr + ".player");
|
||||
UUID player = playerStr == null ? null : UUID.fromString(playerStr);
|
||||
String placedByStr = dataFile.getConfig().getString("data.sync." + locationStr + ".placedBy");
|
||||
UUID lastPlayer = playerStr == null ? null : UUID.fromString(playerStr);
|
||||
UUID placedBy = placedByStr == null ? null : UUID.fromString(placedByStr);
|
||||
|
||||
List<ItemStack> whiteList = (ArrayList<ItemStack>) dataFile.getConfig().getList("data.sync." + locationStr + ".whitelist");
|
||||
List<ItemStack> blackList = (ArrayList<ItemStack>) dataFile.getConfig().getList("data.sync." + locationStr + ".blacklist");
|
||||
@ -126,12 +133,25 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
filter.setVoidList(voidList);
|
||||
filter.setEndPoint(black);
|
||||
|
||||
EHopper hopper = new EHopper(location, levelManager.getLevel(level), player, block, filter, walkOnTeleport);
|
||||
EHopper hopper = new EHopper(location, levelManager.getLevel(level), lastPlayer, placedBy, block, filter, walkOnTeleport);
|
||||
|
||||
hopperManager.addHopper(location, hopper);
|
||||
}
|
||||
}
|
||||
|
||||
// Adding in Boosts
|
||||
if (dataFile.getConfig().contains("data.boosts")) {
|
||||
for (String key : dataFile.getConfig().getConfigurationSection("data.boosts").getKeys(false)) {
|
||||
if (!dataFile.getConfig().contains("data.boosts." + key + ".Player")) continue;
|
||||
BoostData boostData = new BoostData(
|
||||
dataFile.getConfig().getInt("data.boosts." + key + ".Amount"),
|
||||
Long.parseLong(key),
|
||||
UUID.fromString(dataFile.getConfig().getString("data.boosts." + key + ".Player")));
|
||||
|
||||
this.boostManager.addBoostToPlayer(boostData);
|
||||
}
|
||||
}
|
||||
|
||||
}, 10);
|
||||
|
||||
references = new References();
|
||||
@ -197,6 +217,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".level", hopper.getLevel().getLevel());
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".block", hopper.getSyncedBlock() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getSyncedBlock().getLocation()));
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".player", hopper.getLastPlayer() == null ? null : hopper.getLastPlayer().toString());
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".placedBy", hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString());
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".walkOnTeleport", hopper.isWalkOnTeleport());
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".whitelist", hopper.getFilter().getWhiteList());
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".blacklist", hopper.getFilter().getBlackList());
|
||||
@ -204,6 +225,15 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
dataFile.getConfig().set("data.sync." + locationStr + ".black", hopper.getFilter().getEndPoint() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getFilter().getEndPoint().getLocation()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump BoostManager to file.
|
||||
*/
|
||||
for (BoostData boostData : boostManager.getBoosts()) {
|
||||
String endTime = String.valueOf(boostData.getEndTime());
|
||||
dataFile.getConfig().set("data.boosts." + endTime + ".Player", boostData.getPlayer().toString());
|
||||
dataFile.getConfig().set("data.boosts." + endTime + ".Amount", boostData.getMultiplier());
|
||||
}
|
||||
|
||||
//Save to file
|
||||
dataFile.saveConfig();
|
||||
}
|
||||
@ -350,6 +380,10 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
return teleportHandler;
|
||||
}
|
||||
|
||||
public BoostManager getBoostManager() {
|
||||
return boostManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelManager getLevelManager() {
|
||||
return levelManager;
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.songoda.epichoppers.boost;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BoostData {
|
||||
|
||||
private final int multiplier;
|
||||
private final long endTime;
|
||||
private final UUID player;
|
||||
|
||||
public BoostData(int multiplier, long endTime, UUID player) {
|
||||
this.multiplier = multiplier;
|
||||
this.endTime = endTime;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public int getMultiplier() {
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 31 * multiplier;
|
||||
|
||||
result = 31 * result + (this.player == null ? 0 : player.hashCode());
|
||||
result = 31 * result + (int) (endTime ^ (endTime >>> 32));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof BoostData)) return false;
|
||||
|
||||
BoostData other = (BoostData) obj;
|
||||
return multiplier == other.multiplier && endTime == other.endTime
|
||||
&& Objects.equals(player, other.player);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.songoda.epichoppers.boost;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BoostManager {
|
||||
|
||||
private final Set<BoostData> registeredBoosts = new HashSet<>();
|
||||
|
||||
public void addBoostToPlayer(BoostData data) {
|
||||
this.registeredBoosts.add(data);
|
||||
}
|
||||
|
||||
public void removeBoostFromPlayer(BoostData data) {
|
||||
this.registeredBoosts.remove(data);
|
||||
}
|
||||
|
||||
public Set<BoostData> getBoosts() {
|
||||
return Collections.unmodifiableSet(registeredBoosts);
|
||||
}
|
||||
|
||||
public BoostData getBoost(UUID player) {
|
||||
if (player == null) return null;
|
||||
for (BoostData boostData : registeredBoosts) {
|
||||
if (boostData.getPlayer().toString().equals(player.toString())) {
|
||||
if (System.currentTimeMillis() >= boostData.getEndTime()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHoppersPlugin.getInstance(), () -> removeBoostFromPlayer(boostData), 1);
|
||||
}
|
||||
return boostData;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -2,10 +2,7 @@ package com.songoda.epichoppers.command;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.command.commands.CommandEpicHoppers;
|
||||
import com.songoda.epichoppers.command.commands.CommandGive;
|
||||
import com.songoda.epichoppers.command.commands.CommandReload;
|
||||
import com.songoda.epichoppers.command.commands.CommandSettings;
|
||||
import com.songoda.epichoppers.command.commands.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -27,6 +24,7 @@ public class CommandManager implements CommandExecutor {
|
||||
addCommand(new CommandReload(commandEpicHoppers));
|
||||
addCommand(new CommandSettings(commandEpicHoppers));
|
||||
addCommand(new CommandGive(commandEpicHoppers));
|
||||
addCommand(new CommandBoost(commandEpicHoppers));
|
||||
}
|
||||
|
||||
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.songoda.epichoppers.command.commands;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.methods.math.AMath;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.command.AbstractCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class CommandBoost extends AbstractCommand {
|
||||
|
||||
public CommandBoost(AbstractCommand parent) {
|
||||
super("boost", "epichoppers.admin", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length >= 3) {
|
||||
if (Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&cThat player does not exist..."));
|
||||
} else if (!AMath.isInt(args[2])) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&6" + args[2] + " &7is not a number..."));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date currentDate = new Date();
|
||||
c.setTime(currentDate);
|
||||
|
||||
String time = "&7.";
|
||||
|
||||
if (args.length > 3) {
|
||||
if (args[3].contains("m:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.MINUTE, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " minutes&7.";
|
||||
} else if (args[3].contains("h:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " hours&7.";
|
||||
} else if (args[3].contains("d:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]) * 24);
|
||||
time = " &7for &6" + arr2[1] + " days&7.";
|
||||
} else if (args[3].contains("y:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.YEAR, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " years&7.";
|
||||
} else {
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&7" + args[3] + " &7is invalid."));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
c.add(Calendar.YEAR, 10);
|
||||
}
|
||||
|
||||
BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId());
|
||||
instance.getBoostManager().addBoostToPlayer(boostData);
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7hoppers transfer rates by &6" + args[2] + "x" + time));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&7Syntax error..."));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -15,13 +15,14 @@ public class CommandEpicHoppers extends AbstractCommand {
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(TextComponent.formatText("&f>>&m------------&6&l EpicHoppers Help &f&m------------&f<<"));
|
||||
sender.sendMessage(TextComponent.formatText(" &7" + instance.getDescription().getVersion() + " Created by &5&l&oBrianna"));
|
||||
sender.sendMessage(TextComponent.formatText(" &7Version " + instance.getDescription().getVersion() + " Created by &5&l&oBrianna"));
|
||||
|
||||
sender.sendMessage(TextComponent.formatText("&6/EpicHoppers&7 - Displays this page."));
|
||||
if (sender.hasPermission("epichoppers.admin")) {
|
||||
sender.sendMessage(TextComponent.formatText("&6/eh book [player]&7- Gives Sync Touch book to you or a player."));
|
||||
sender.sendMessage(TextComponent.formatText("&6/eh give [player] [level]&7 - Give a leveled hopper to a player."));
|
||||
sender.sendMessage(TextComponent.formatText("&6/eh settings&7 - Edit the EpicHoppers Settings."));
|
||||
sender.sendMessage(TextComponent.formatText("&6/es boost <player> <multiplier> [m:minute, h:hour, d:day, y:year]&7 - This allows you to boost a players hoppers be a multiplier (Put 2 for double, 3 for triple and so on)."));
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epichoppers.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.*;
|
||||
@ -166,7 +167,9 @@ public class HopHandler {
|
||||
continue;
|
||||
}
|
||||
|
||||
int amt = hopper.getLevel().getAmount();
|
||||
BoostData boostData = instance.getBoostManager().getBoost(hopper.getPlacedBy());
|
||||
|
||||
int amt = hopper.getLevel().getAmount() * (boostData == null ? 1 : boostData.getMultiplier());
|
||||
|
||||
ItemStack[] is = hopperBlock.getInventory().getContents();
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.methods.formatting.TimeComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Filter;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.player.MenuType;
|
||||
import com.songoda.epichoppers.player.PlayerData;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
@ -30,22 +33,24 @@ public class EHopper implements Hopper {
|
||||
private Location location;
|
||||
private com.songoda.epichoppers.api.hopper.Level level;
|
||||
private UUID lastPlayer;
|
||||
private UUID placedBy;
|
||||
private Block syncedBlock;
|
||||
private Filter filter;
|
||||
private boolean walkOnTeleport;
|
||||
|
||||
|
||||
public EHopper(Location location, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, Block syncedBlock, Filter filter, boolean walkOnTeleport) {
|
||||
public EHopper(Location location, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, boolean walkOnTeleport) {
|
||||
this.location = location;
|
||||
this.level = level;
|
||||
this.syncedBlock = syncedBlock;
|
||||
this.filter = filter;
|
||||
this.lastPlayer = lastPlayer;
|
||||
this.placedBy = placedBy;
|
||||
this.walkOnTeleport = walkOnTeleport;
|
||||
}
|
||||
|
||||
public EHopper(Block block, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, Block syncedBlock, Filter filter, boolean walkOnTeleport) {
|
||||
this(block.getLocation(), level, lastPlayer, syncedBlock, filter, walkOnTeleport);
|
||||
public EHopper(Block block, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, boolean walkOnTeleport) {
|
||||
this(block.getLocation(), level, lastPlayer, placedBy, syncedBlock, filter, walkOnTeleport);
|
||||
}
|
||||
|
||||
public void overview(Player player) {
|
||||
@ -97,6 +102,14 @@ public class EHopper implements Hopper {
|
||||
lore.addAll(nextLevel.getDescription());
|
||||
}
|
||||
|
||||
BoostData boostData = instance.getBoostManager().getBoost(placedBy);
|
||||
if (boostData != null) {
|
||||
parts = instance.getLocale().getMessage("interface.hopper.boostedstats", Integer.toString(boostData.getMultiplier()), TimeComponent.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|");
|
||||
lore.add("");
|
||||
for (String line : parts)
|
||||
lore.add(TextComponent.formatText(line));
|
||||
}
|
||||
|
||||
itemmeta.setLore(lore);
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
@ -491,6 +504,11 @@ public class EHopper implements Hopper {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getPlacedBy() {
|
||||
return placedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getLastPlayer() {
|
||||
return lastPlayer;
|
||||
|
@ -28,7 +28,7 @@ public class EHopperManager implements HopperManager {
|
||||
@Override
|
||||
public Hopper getHopper(Location location) {
|
||||
if (!registeredHoppers.containsKey(roundLocation(location))) {
|
||||
addHopper(location, new EHopper(location, EpicHoppersPlugin.getInstance().getLevelManager().getLowestLevel(), null, null, new EFilter(), false));
|
||||
addHopper(location, new EHopper(location, EpicHoppersPlugin.getInstance().getLevelManager().getLowestLevel(), null, null, null, new EFilter(), false));
|
||||
}
|
||||
return registeredHoppers.get(roundLocation(location));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
ItemStack item = e.getItemInHand().clone();
|
||||
|
||||
instance.getHopperManager().addHopper(e.getBlock().getLocation(), new EHopper(e.getBlock(), instance.getLevelFromItem(item), e.getPlayer().getUniqueId(), null, new EFilter(), false));
|
||||
instance.getHopperManager().addHopper(e.getBlock().getLocation(), new EHopper(e.getBlock(), instance.getLevelFromItem(item), e.getPlayer().getUniqueId(), e.getPlayer().getUniqueId(),null, new EFilter(), false));
|
||||
|
||||
} catch (Exception ee) {
|
||||
Debugger.runReport(ee);
|
||||
|
@ -7,6 +7,7 @@ general.nametag.nameformat = "&eLevel %level% &fHopper"
|
||||
|
||||
#Interface Messages
|
||||
|
||||
interface.hopper.boostedstats = "&a&lCurrently boosted!|&7Item transfer rate multiplied by &6%amount%x&7.|&7Expires in &6%time%&7."
|
||||
interface.hopper.upgradewithxp = "&aUpgrade with XP"
|
||||
interface.hopper.upgradewithxplore = "&7Cost: &a%cost% Levels"
|
||||
interface.hopper.upgradewitheconomy = "&aUpgrade with ECO"
|
||||
|
Loading…
Reference in New Issue
Block a user