mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
Removes dependency on NMS
This commit is contained in:
parent
2551d184ca
commit
adcccb10e5
9
pom.xml
9
pom.xml
@ -50,11 +50,6 @@
|
|||||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>nms-repo</id>
|
|
||||||
<url>https://repo.codemc.org/repository/nms/</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
@ -140,8 +135,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.17.1-R0.1-SNAPSHOT</version>
|
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -175,9 +175,9 @@ public class LoginProcess extends FreedomService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Whitelist
|
// Whitelist
|
||||||
if (plugin.si.isWhitelisted())
|
if (server.isWhitelistEnforced())
|
||||||
{
|
{
|
||||||
if (!plugin.si.getWhitelisted().contains(username.toLowerCase()))
|
if (!player.isWhitelisted())
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package me.totalfreedom.totalfreedommod;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import joptsimple.internal.Strings;
|
import com.google.common.base.Strings;
|
||||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
|
||||||
|
|
||||||
public class ServerInterface extends FreedomService
|
|
||||||
{
|
|
||||||
public static final String COMPILE_NMS_VERSION = "v1_17_R1";
|
|
||||||
|
|
||||||
public static void warnVersion()
|
|
||||||
{
|
|
||||||
final String nms = FUtil.getNMSVersion();
|
|
||||||
|
|
||||||
if (!COMPILE_NMS_VERSION.equals(nms))
|
|
||||||
{
|
|
||||||
FLog.warning(TotalFreedomMod.pluginName + " is compiled for " + COMPILE_NMS_VERSION + " but the server is running version " + nms + "!");
|
|
||||||
FLog.warning("This might result in unexpected behaviour!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public int purgeWhitelist()
|
|
||||||
{
|
|
||||||
String[] whitelisted = getServer().getPlayerList().getWhitelisted();
|
|
||||||
int size = whitelisted.length;
|
|
||||||
for (EntityPlayer player : getServer().getPlayerList().getPlayers())
|
|
||||||
{
|
|
||||||
getServer().getPlayerList().getWhitelist().remove(player.getProfile());
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
getServer().getPlayerList().getWhitelist().save();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
FLog.warning("Could not purge the whitelist!");
|
|
||||||
FLog.warning(ex);
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWhitelisted()
|
|
||||||
{
|
|
||||||
return getServer().getPlayerList().getHasWhitelist();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<?> getWhitelisted()
|
|
||||||
{
|
|
||||||
return Arrays.asList(getServer().getPlayerList().getWhitelisted());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion()
|
|
||||||
{
|
|
||||||
return getServer().getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
private MinecraftServer getServer()
|
|
||||||
{
|
|
||||||
return ((CraftServer)Bukkit.getServer()).getServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -7,8 +8,13 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.server.ServerListPingEvent;
|
import org.bukkit.event.server.ServerListPingEvent;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
public class ServerPing extends FreedomService
|
public class ServerPing extends FreedomService
|
||||||
{
|
{
|
||||||
|
private final Gson gson = new Gson();
|
||||||
|
private final VersionMeta meta = gson.fromJson(new InputStreamReader(Bukkit.class.getClassLoader().getResourceAsStream("version.json")),VersionMeta.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart()
|
public void onStart()
|
||||||
{
|
{
|
||||||
@ -54,7 +60,7 @@ public class ServerPing extends FreedomService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion());
|
String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", meta.id);
|
||||||
baseMotd = baseMotd.replace("\\n", "\n");
|
baseMotd = baseMotd.replace("\\n", "\n");
|
||||||
baseMotd = FUtil.colorize(baseMotd);
|
baseMotd = FUtil.colorize(baseMotd);
|
||||||
|
|
||||||
@ -73,4 +79,9 @@ public class ServerPing extends FreedomService
|
|||||||
|
|
||||||
event.setMotd(motd.toString().trim());
|
event.setMotd(motd.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class VersionMeta
|
||||||
|
{
|
||||||
|
private String id;
|
||||||
|
}
|
||||||
}
|
}
|
@ -14,7 +14,6 @@ import me.totalfreedom.totalfreedommod.blocking.InteractBlocker;
|
|||||||
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
|
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
|
||||||
import me.totalfreedom.totalfreedommod.blocking.PVPBlocker;
|
import me.totalfreedom.totalfreedommod.blocking.PVPBlocker;
|
||||||
import me.totalfreedom.totalfreedommod.blocking.PotionBlocker;
|
import me.totalfreedom.totalfreedommod.blocking.PotionBlocker;
|
||||||
import me.totalfreedom.totalfreedommod.blocking.SignBlocker;
|
|
||||||
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
|
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
|
||||||
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
|
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
|
||||||
import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge;
|
import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge;
|
||||||
@ -54,7 +53,6 @@ import org.bukkit.generator.ChunkGenerator;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spigotmc.SpigotConfig;
|
|
||||||
|
|
||||||
public class TotalFreedomMod extends JavaPlugin
|
public class TotalFreedomMod extends JavaPlugin
|
||||||
{
|
{
|
||||||
@ -74,7 +72,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
// Command Loader
|
// Command Loader
|
||||||
public CommandLoader cl;
|
public CommandLoader cl;
|
||||||
// Services
|
// Services
|
||||||
public ServerInterface si;
|
|
||||||
public WorldManager wm;
|
public WorldManager wm;
|
||||||
public LogViewer lv;
|
public LogViewer lv;
|
||||||
public AdminList al;
|
public AdminList al;
|
||||||
@ -121,7 +118,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
public Trailer tr;
|
public Trailer tr;
|
||||||
public HTTPDaemon hd;
|
public HTTPDaemon hd;
|
||||||
public WorldRestrictions wr;
|
public WorldRestrictions wr;
|
||||||
public SignBlocker snp;
|
|
||||||
public EntityWiper ew;
|
public EntityWiper ew;
|
||||||
public Sitter st;
|
public Sitter st;
|
||||||
public VanishHandler vh;
|
public VanishHandler vh;
|
||||||
@ -176,9 +172,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
final MethodTimer timer = new MethodTimer();
|
final MethodTimer timer = new MethodTimer();
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
// Warn if we're running on a wrong version
|
|
||||||
ServerInterface.warnVersion();
|
|
||||||
|
|
||||||
// Delete unused files
|
// Delete unused files
|
||||||
FUtil.deleteCoreDumps();
|
FUtil.deleteCoreDumps();
|
||||||
FUtil.deleteFolder(new File("./_deleteme"));
|
FUtil.deleteFolder(new File("./_deleteme"));
|
||||||
@ -211,13 +204,10 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
FLog.info("Started " + fsh.getServiceAmount() + " services.");
|
FLog.info("Started " + fsh.getServiceAmount() + " services.");
|
||||||
|
|
||||||
timer.update();
|
timer.update();
|
||||||
FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
|
FLog.info("Version " + pluginVersion + " enabled in " + timer.getTotal() + "ms");
|
||||||
|
|
||||||
// Metrics @ https://bstats.org/plugin/bukkit/TotalFreedomMod/2966
|
// Metrics @ https://bstats.org/plugin/bukkit/TotalFreedomMod/2966
|
||||||
new Metrics(this, 2966);
|
new Metrics(this, 2966);
|
||||||
|
|
||||||
// little workaround to stop spigot from autorestarting - causing AMP to detach from process.
|
|
||||||
SpigotConfig.config.set("settings.restart-on-crash", false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -296,7 +286,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
private void initServices()
|
private void initServices()
|
||||||
{
|
{
|
||||||
// Start services
|
// Start services
|
||||||
si = new ServerInterface();
|
|
||||||
wm = new WorldManager();
|
wm = new WorldManager();
|
||||||
lv = new LogViewer();
|
lv = new LogViewer();
|
||||||
sql = new SQLite();
|
sql = new SQLite();
|
||||||
@ -324,7 +313,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
im = new IndefiniteBanList();
|
im = new IndefiniteBanList();
|
||||||
pem = new PermissionManager();
|
pem = new PermissionManager();
|
||||||
gr = new GameRuleHandler();
|
gr = new GameRuleHandler();
|
||||||
snp = new SignBlocker();
|
|
||||||
ew = new EntityWiper();
|
ew = new EntityWiper();
|
||||||
st = new Sitter();
|
st = new Sitter();
|
||||||
vh = new VanishHandler();
|
vh = new VanishHandler();
|
||||||
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
|
||||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
@ -265,4 +267,10 @@ public class EventBlocker extends FreedomService
|
|||||||
FUtil.fixCommandVoid(event.getEntity());
|
FUtil.fixCommandVoid(event.getEntity());
|
||||||
event.setDeathMessage(event.getDeathMessage());
|
event.setDeathMessage(event.getDeathMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSignInteract(PlayerSignCommandPreprocessEvent event)
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
package me.totalfreedom.totalfreedommod.blocking;
|
|
||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Tag;
|
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
//codebeat:disable[LOC,ABC]
|
|
||||||
|
|
||||||
public class SignBlocker extends FreedomService
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onStart()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
|
||||||
public void onPlayerPlaceBlock(BlockPlaceEvent event)
|
|
||||||
{
|
|
||||||
|
|
||||||
final Player player = event.getPlayer();
|
|
||||||
if (Tag.SIGNS.getValues().contains(event.getBlock().getType()))
|
|
||||||
{
|
|
||||||
ItemStack sign = event.getItemInHand();
|
|
||||||
net.minecraft.world.item.ItemStack nmsSign = CraftItemStack.asNMSCopy(sign);
|
|
||||||
NBTTagCompound compound = (nmsSign.hasTag()) ? nmsSign.getTag() : new NBTTagCompound();
|
|
||||||
assert compound != null;
|
|
||||||
NBTTagCompound bet = compound.getCompound("BlockEntityTag");
|
|
||||||
String line1 = bet.getString("Text1");
|
|
||||||
String line2 = bet.getString("Text2");
|
|
||||||
String line3 = bet.getString("Text3");
|
|
||||||
String line4 = bet.getString("Text4");
|
|
||||||
if (line1.contains("run_command") || line2.contains("run_command") || line3.contains("run_command") || line4.contains("run_command"))
|
|
||||||
{
|
|
||||||
player.sendMessage(ChatColor.GRAY + "You are not allowed to place command signs.");
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPlayerInteractSign(PlayerInteractEvent event)
|
|
||||||
{
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getClickedBlock() != null && Tag.SIGNS.getValues().contains(event.getClickedBlock().getType()))
|
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,10 +2,10 @@ package me.totalfreedom.totalfreedommod.blocking.command;
|
|||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.spigotmc.SpigotConfig;
|
|
||||||
|
|
||||||
public class CommandBlockerEntry
|
public class CommandBlockerEntry
|
||||||
{
|
{
|
||||||
@ -45,7 +45,7 @@ public class CommandBlockerEntry
|
|||||||
}
|
}
|
||||||
if (action == CommandBlockerAction.BLOCK_UNKNOWN)
|
if (action == CommandBlockerAction.BLOCK_UNKNOWN)
|
||||||
{
|
{
|
||||||
sender.sendMessage(SpigotConfig.unknownCommandMessage);
|
sender.sendMessage(Bukkit.spigot().getSpigotConfig().getString("messages.unknown-command"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FUtil.playerMsg(sender, FUtil.colorize(message));
|
FUtil.playerMsg(sender, FUtil.colorize(message));
|
||||||
|
@ -1,266 +0,0 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.SplittableRandom;
|
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
|
||||||
@CommandParameters(description = "Modify the current item you are holding.", usage = "/<command> <name <message> | lore <message> | enchant <enchantment> <level> | potion <effect> <duration> <amplifier> | attribute <name> <amount> | clear>", aliases = "mi")
|
|
||||||
public class Command_modifyitem extends FreedomCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
if (args.length < 1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack item = playerSender.getInventory().getItemInMainHand();
|
|
||||||
if (item.getType().equals(Material.AIR))
|
|
||||||
{
|
|
||||||
msg("You must have an item in your hand!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("clear"))
|
|
||||||
{
|
|
||||||
item.setItemMeta(null);
|
|
||||||
playerSender.getInventory().setItemInMainHand(item);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length < 2)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
assert meta != null;
|
|
||||||
switch (args[0])
|
|
||||||
{
|
|
||||||
case "name":
|
|
||||||
String name = FUtil.colorize(StringUtils.join(args, " ", 1, args.length));
|
|
||||||
meta.setDisplayName(name);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "lore":
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
for (String line : StringUtils.join(args, " ", 1, args.length).split("\\\\n"))
|
|
||||||
{
|
|
||||||
lore.add(FUtil.colorize(line));
|
|
||||||
}
|
|
||||||
meta.setLore(lore);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "enchant":
|
|
||||||
if (args.length < 3)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Enchantment enchantment = Enchantment.getByName(args[1].toUpperCase());
|
|
||||||
if (enchantment == null)
|
|
||||||
{
|
|
||||||
msg("Invalid enchantment. Please run /enchant list for a list of valid enchantments.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int level;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
level = Integer.parseInt(args[2]);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
msg("The level specified is not a valid integer.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
meta.addEnchant(enchantment, level, true);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "potion":
|
|
||||||
{
|
|
||||||
if (!item.getType().equals(Material.POTION) & !item.getType().equals(Material.SPLASH_POTION) & !item.getType().equals(Material.LINGERING_POTION) & !item.getType().equals(Material.TIPPED_ARROW))
|
|
||||||
{
|
|
||||||
msg("This item can not have potion effects added to it.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length < 4)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PotionEffectType type = PotionEffectType.getByName(args[1]);
|
|
||||||
if (type == null)
|
|
||||||
{
|
|
||||||
msg("Invalid potion effect. Please run /potion list for a list of valid potion effects.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int duration;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
duration = Math.max(1, Math.min(1000000, Integer.parseInt(args[2])));
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
msg("The duration specified is not a valid integer.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int amplifier;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
amplifier = Math.max(1, Math.min(256, Integer.parseInt(args[2])));
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
msg("The amplifier specified is not a valid integer.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PotionMeta potionMeta = (PotionMeta)meta;
|
|
||||||
potionMeta.addCustomEffect(type.createEffect(duration, amplifier), true);
|
|
||||||
item.setItemMeta(potionMeta);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "attribute":
|
|
||||||
if (args.length < 3)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
|
||||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
|
||||||
NBTTagList modifiers = getAttributeList(nmsStack);
|
|
||||||
NBTTagCompound cmpnd = new NBTTagCompound();
|
|
||||||
Attribute attribute = Attribute.getByName(args[1].toUpperCase());
|
|
||||||
if (attribute == null)
|
|
||||||
{
|
|
||||||
msg("Invalid attribute. Please run /attributelist for a list of valid attributes.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
cmpnd.setString("AttributeName", attribute.getAttribute());
|
|
||||||
cmpnd.setString("Name", attribute.getAttribute());
|
|
||||||
double amount;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
amount = Double.parseDouble(args[2]);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
msg("The amount specified is not a valid integer.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Double.isNaN(amount))
|
|
||||||
{
|
|
||||||
msg("The amount specified is illegal.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
cmpnd.setDouble("Amount", amount);
|
|
||||||
cmpnd.setInt("Operation", 0);
|
|
||||||
SplittableRandom random = new SplittableRandom();
|
|
||||||
cmpnd.setIntArray("UUID", new int[]
|
|
||||||
{
|
|
||||||
random.nextInt(),
|
|
||||||
random.nextInt(),
|
|
||||||
random.nextInt(),
|
|
||||||
random.nextInt()
|
|
||||||
});
|
|
||||||
cmpnd.setString("Slot", "mainhand");
|
|
||||||
modifiers.add(cmpnd);
|
|
||||||
assert compound != null;
|
|
||||||
compound.set("AttributeModifiers", modifiers);
|
|
||||||
nmsStack.setTag(compound);
|
|
||||||
item = CraftItemStack.asBukkitCopy(nmsStack);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
playerSender.getInventory().setItemInMainHand(item);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NBTTagList getAttributeList(net.minecraft.world.item.ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.getTag() == null)
|
|
||||||
{
|
|
||||||
stack.setTag(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
NBTTagList attr = stack.getTag().getList("AttributeModifiers", 10);
|
|
||||||
if (attr == null)
|
|
||||||
{
|
|
||||||
stack.getTag().set("AttributeModifiers", new NBTTagList());
|
|
||||||
}
|
|
||||||
return stack.getTag().getList("AttributeModifiers", 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum Attribute
|
|
||||||
{
|
|
||||||
GENERIC_MAX_HEALTH("GENERIC_MAX_HEALTH", "generic.max_health"),
|
|
||||||
GENERIC_FOLLOW_RANGE("GENERIC_FOLLOW_RANGE", "generic.follow_range"),
|
|
||||||
GENERIC_KNOCKBACK_RESISTANCE("GENERIC_KNOCKBACK_RESISTANCE", "generic.knockback_resistance"),
|
|
||||||
GENERIC_MOVEMENT_SPEED("GENERIC_MOVEMENT_SPEED", "generic.movement_speed"),
|
|
||||||
GENERIC_FLYING_SPEED("GENERIC_FLYING_SPEED", "generic.flying_speed"),
|
|
||||||
GENERIC_ATTACK_DAMAGE("GENERIC_ATTACK_DAMAGE", "generic.attack_damage"),
|
|
||||||
GENERIC_ATTACK_SPEED("GENERIC_ATTACK_SPEED", "generic.attack_speed"),
|
|
||||||
GENERIC_ARMOR("GENERIC_ARMOR", "generic.armor"),
|
|
||||||
GENERIC_ARMOR_TOUGHNESS("GENERIC_ARMOR_TOUGHNESS", "generic.armor_toughmess"),
|
|
||||||
GENERIC_LUCK("GENERIC_LUCK", "generic.luck"),
|
|
||||||
HORSE_JUMP_STRENGTH("GENERIC_MAX_HEALTH", "horse.jump_strength"),
|
|
||||||
ZOMBIE_SPAWN_REINFORCEMENTS("ZOMBIE_SPAWN_REINFORCEMENTS", "zombie.spawn_reinforcements");
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String attribute;
|
|
||||||
|
|
||||||
Attribute(String name, String attribute)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
this.attribute = attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Attribute getByName(String name)
|
|
||||||
{
|
|
||||||
for (Attribute attr : Attribute.values())
|
|
||||||
{
|
|
||||||
if (attr.toString().toUpperCase().equals(name))
|
|
||||||
{
|
|
||||||
return attr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAttribute()
|
|
||||||
{
|
|
||||||
return attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -158,7 +158,7 @@ public class Command_whitelist extends FreedomCommand
|
|||||||
if (args[0].equalsIgnoreCase("purge"))
|
if (args[0].equalsIgnoreCase("purge"))
|
||||||
{
|
{
|
||||||
FUtil.adminAction(sender.getName(), "Removing all players from the whitelist", false);
|
FUtil.adminAction(sender.getName(), "Removing all players from the whitelist", false);
|
||||||
msg("Removed " + plugin.si.purgeWhitelist() + " players from the whitelist.");
|
msg("Removed " + purge() + " players from the whitelist.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -198,10 +198,21 @@ public class Command_whitelist extends FreedomCommand
|
|||||||
public List<String> getWhitelistedNames()
|
public List<String> getWhitelistedNames()
|
||||||
{
|
{
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
for (Object name : plugin.si.getWhitelisted())
|
for (OfflinePlayer player : server.getWhitelistedPlayers())
|
||||||
{
|
{
|
||||||
names.add(String.valueOf(name));
|
names.add(player.getName());
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int purge()
|
||||||
|
{
|
||||||
|
int removed = 0;
|
||||||
|
for (OfflinePlayer player : server.getWhitelistedPlayers())
|
||||||
|
{
|
||||||
|
player.setWhitelisted(false);
|
||||||
|
removed++;
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user