From 0797702dc81301c17835d5f83fde01fdfdb93b9f Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 25 Jul 2018 20:08:11 +0100 Subject: [PATCH 01/15] First pass at a 1.13 release. The basics appear to work --- pom.xml | 6 +- .../totalfreedommod/FrontDoor.java | 5 +- .../totalfreedommod/ServerInterface.java | 2 +- .../blocking/BlockBlocker.java | 2 - .../blocking/InteractBlocker.java | 3 +- .../totalfreedommod/caging/CageData.java | 4 +- .../totalfreedommod/command/Command_cage.java | 16 +- .../command/Command_dispfill.java | 11 +- .../totalfreedommod/command/Command_mp44.java | 2 +- .../totalfreedommod/command/Command_ro.java | 11 +- .../command/Command_setlever.java | 9 +- .../command/Command_whohas.java | 15 +- .../totalfreedommod/fun/ItemFun.java | 8 +- .../totalfreedommod/fun/Jumppads.java | 2 +- .../totalfreedommod/fun/Trailer.java | 5 +- .../rollback/RollbackEntry.java | 11 +- .../rollback/RollbackManager.java | 2 +- .../util/DepreciationAggregator.java | 20 +- .../totalfreedommod/util/FUtil.java | 19 ++ .../totalfreedommod/world/AdminWorld.java | 2 +- .../world/CleanroomBlockPopulator.java | 61 ------ .../world/CleanroomChunkGenerator.java | 205 ++++++------------ .../totalfreedommod/world/Flatlands.java | 3 +- src/main/resources/plugin.yml | 1 + 24 files changed, 123 insertions(+), 302 deletions(-) delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java diff --git a/pom.xml b/pom.xml index 703906cff..f800c25c4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ me.totalfreedom totalfreedom - 5.0.1 + 5.0.2 jar @@ -77,13 +77,13 @@ org.projectlombok lombok - 1.16.6 + 1.16.16 org.spigotmc spigot-api - 1.12-pre5-SNAPSHOT + 1.13-R0.1-SNAPSHOT compile diff --git a/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java b/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java index 3e1682071..56c0ae01c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java @@ -463,7 +463,7 @@ else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) continue; } - block.setType(Material.SIGN_POST); + block.setType(Material.SIGN); org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState(); org.bukkit.material.Sign signData = (org.bukkit.material.Sign) sign.getData(); @@ -541,7 +541,8 @@ else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) FUtil.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true); Location targetPos = player.getLocation().clone().add(0, 1, 0); - playerdata.getCageData().cage(targetPos, Material.SKULL, Material.AIR); + playerdata.getCageData().cage(targetPos, Material.SKELETON_SKULL, Material.AIR); + break; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java index 90df9edf7..117eda500 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java @@ -6,7 +6,7 @@ public class ServerInterface extends FreedomService { - public static final String COMPILE_NMS_VERSION = "v1_12_R1"; + public static final String COMPILE_NMS_VERSION = "v1_13_R1"; public ServerInterface(TotalFreedomMod plugin) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java index bd469ed13..ede43745a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java @@ -39,7 +39,6 @@ public void onBlockPlace(BlockPlaceEvent event) switch (event.getBlockPlaced().getType()) { case LAVA: - case STATIONARY_LAVA: { if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) { @@ -57,7 +56,6 @@ public void onBlockPlace(BlockPlaceEvent event) break; } case WATER: - case STATIONARY_WATER: { if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index 30dec0d22..bf586276a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -83,7 +83,7 @@ private void handleRightClick(PlayerInteractEvent event) break; } - case EXPLOSIVE_MINECART: + case TNT_MINECART: { if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) { @@ -97,7 +97,6 @@ private void handleRightClick(PlayerInteractEvent event) } case SIGN: - case SIGN_POST: case WALL_SIGN: { player.sendMessage(ChatColor.GRAY + "Sign interaction is currently disabled."); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java b/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java index 53e4c9039..3aa515ca0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java @@ -165,7 +165,7 @@ public static void generateHollowCube(Location location, int length, Material ma final Block block = center.getRelative(xOffset, yOffset, zOffset); - if (material != Material.SKULL) + if (material != Material.SKELETON_SKULL) { // Glowstone light if (material != Material.GLASS && xOffset == 0 && yOffset == 2 && zOffset == 0) @@ -184,7 +184,7 @@ public static void generateHollowCube(Location location, int length, Material ma continue; } - block.setType(Material.SKULL); + block.setType(Material.SKELETON_SKULL); final Skull skull = (Skull) block.getState(); skull.setSkullType(SkullType.PLAYER); skull.setOwner("Prozza"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java index 3c2d466d5..a9812235b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java @@ -70,7 +70,7 @@ else if ("purge".equals(args[0])) { if ("darth".equalsIgnoreCase(args[1])) { - outerMaterial = Material.SKULL; + outerMaterial = Material.SKELETON_SKULL; } else if (Material.matchMaterial(args[1]) != null) { @@ -79,24 +79,12 @@ else if (Material.matchMaterial(args[1]) != null) } } - if (args.length >= 3) - { - if (args[2].equalsIgnoreCase("water")) - { - innerMaterial = Material.STATIONARY_WATER; - } - else if (args[2].equalsIgnoreCase("lava")) - { - innerMaterial = Material.STATIONARY_LAVA; - } - } - Location targetPos = player.getLocation().clone().add(0, 1, 0); playerdata.getCageData().cage(targetPos, outerMaterial, innerMaterial); player.setGameMode(GameMode.SURVIVAL); - if (outerMaterial != Material.SKULL) + if (outerMaterial != Material.SKELETON_SKULL) { FUtil.adminAction(sender.getName(), "Caging " + player.getName(), true); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java index 8d0e12e33..d877b0579 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java @@ -44,16 +44,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin for (final String searchItem : itemsRaw) { Material material = Material.matchMaterial(searchItem); - if (material == null) - { - try - { - material = DepreciationAggregator.getMaterial(Integer.parseInt(searchItem)); - } - catch (NumberFormatException ex) - { - } - } + if (material != null) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java index 97cf6ee22..6f34ab275 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java @@ -38,7 +38,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin msg("mp44 is ARMED! Left click with gunpowder to start firing, left click again to quit.", ChatColor.GREEN); msg("Type /mp44 sling to disable. -by Madgeek1450", ChatColor.GREEN); - playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.SULPHUR, 1)); + playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.GUNPOWDER, 1)); } else { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java index 40cdb49d2..202a92085 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java @@ -33,16 +33,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin for (String materialName : StringUtils.split(args[0], ",")) { Material fromMaterial = Material.matchMaterial(materialName); - if (fromMaterial == null) - { - try - { - fromMaterial = DepreciationAggregator.getMaterial(Integer.parseInt(materialName)); - } - catch (NumberFormatException ex) - { - } - } + if (fromMaterial == null || fromMaterial == Material.AIR || !fromMaterial.isBlock()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlever.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlever.java index 27df9e022..3abfb5ed8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlever.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlever.java @@ -7,9 +7,11 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.material.Lever; @CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH) @CommandParameters(description = "Set the on/off state of the lever at position x, y, z in world 'worldname'.", usage = "/ ") @@ -63,10 +65,11 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (targetBlock.getType() == Material.LEVER) { - org.bukkit.material.Lever lever = DepreciationAggregator.makeLeverWithData(DepreciationAggregator.getData_Block(targetBlock)); + BlockState state = targetBlock.getState(); + Lever lever = (Lever) state.getData(); lever.setPowered(leverOn); - DepreciationAggregator.setData_Block(targetBlock, DepreciationAggregator.getData_MaterialData(lever)); - targetBlock.getState().update(); + state.setData(lever); + state.update(); } else { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java index 9cc2e2550..a4dac855f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -28,20 +27,10 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin final String materialName = args[0]; Material material = Material.matchMaterial(materialName); - if (material == null) - { - try - { - material = DepreciationAggregator.getMaterial(Integer.parseInt(materialName)); - } - catch (NumberFormatException ex) - { - } - } if (material == null) { - msg("Invalid block: " + materialName, ChatColor.RED); + msg("Invalid item: " + materialName, ChatColor.RED); return true; } @@ -70,4 +59,4 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin return true; } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index 076e3aed7..ce995ea74 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -56,7 +56,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) switch (event.getMaterial()) { - case RAW_FISH: + case TROPICAL_FISH: { final int RADIUS_HIT = 5; final int STRENGTH = 4; @@ -77,7 +77,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) } player.sendMessage(msg.toString()); - player.getEquipment().getItemInMainHand().setType(Material.POTATO_ITEM); + player.getEquipment().getItemInMainHand().setType(Material.POTATO); break; } @@ -126,7 +126,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) break; } - case CARROT_ITEM: + case CARROT: { if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { @@ -209,7 +209,7 @@ public void run() break; } - case SULPHUR: + case GUNPOWDER: { if (!fPlayer.isMP44Armed()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java index 2385bd214..a9063ded7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java @@ -16,7 +16,7 @@ public class Jumppads extends FreedomService { - public static final Material BLOCK_ID = Material.WOOL; + public static final Material BLOCK_ID = Material.WHITE_WOOL; public static final double DAMPING_COEFFICIENT = 0.8; // private final Map pushMap = Maps.newHashMap(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java index 78e26274a..033f3c4fc 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java @@ -7,7 +7,7 @@ import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; -import org.bukkit.Material; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -60,8 +60,7 @@ public void onPlayerMove(PlayerMoveEvent event) return; } - fromBlock.setType(Material.WOOL); - DepreciationAggregator.setData_Block(fromBlock, (byte) random.nextInt(16)); + fromBlock.setType(FUtil.WOOL_COLORS.get(random.nextInt(FUtil.WOOL_COLORS.size()))); } public void remove(Player player) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackEntry.java index fc4dcc319..8af0ac592 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackEntry.java @@ -5,6 +5,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.data.BlockData; import org.bukkit.block.Block; public class RollbackEntry @@ -16,7 +17,7 @@ public class RollbackEntry public final int x; public final short y; public final int z; - public final byte data; + public final BlockData data; public final Material blockMaterial; private final boolean isBreak; @@ -33,13 +34,13 @@ public RollbackEntry(String author, Block block, EntryType entryType) if (entryType == EntryType.BLOCK_BREAK) { this.blockMaterial = block.getType(); - this.data = DepreciationAggregator.getData_Block(block); + this.data = block.getBlockData(); this.isBreak = true; } else { this.blockMaterial = block.getType(); - this.data = DepreciationAggregator.getData_Block(block); + this.data = block.getBlockData(); this.isBreak = false; } } @@ -73,7 +74,7 @@ public void restore() if (isBreak) { block.setType(getMaterial()); - DepreciationAggregator.setData_Block(block, data); + block.setBlockData(data); } else { @@ -92,7 +93,7 @@ public void redo() else { block.setType(getMaterial()); - DepreciationAggregator.setData_Block(block, data); + block.setBlockData(data); } } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackManager.java b/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackManager.java index 4161dfde9..9b6e1e94f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rollback/RollbackManager.java @@ -248,7 +248,7 @@ public void onPlayerInteract(PlayerInteractEvent event) for (RollbackEntry entry : entries) { FUtil.playerMsg(player, " - " + ChatColor.BLUE + entry.author + " " + entry.getType() + " " - + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == 0 ? "" : ":" + entry.data)); + + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == null ? "" : ":" + entry.data)); } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/DepreciationAggregator.java b/src/main/java/me/totalfreedom/totalfreedommod/util/DepreciationAggregator.java index a404deab4..a75d00b33 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/DepreciationAggregator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/DepreciationAggregator.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.util; import java.util.HashSet; +import java.util.UUID; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.Server; @@ -13,7 +14,7 @@ public class DepreciationAggregator { - public static Block getTargetBlock(LivingEntity entity, HashSet transparent, int maxDistance) + public static Block getTargetBlock(LivingEntity entity, HashSet transparent, int maxDistance) { return entity.getTargetBlock(transparent, maxDistance); } @@ -23,11 +24,6 @@ public static OfflinePlayer getOfflinePlayer(Server server, String name) return server.getOfflinePlayer(name); } - public static Material getMaterial(int id) - { - return Material.getMaterial(id); - } - public static byte getData_MaterialData(MaterialData md) { return md.getData(); @@ -43,23 +39,13 @@ public static byte getData_Block(Block block) return block.getData(); } - public static void setData_Block(Block block, byte data) - { - block.setData(data); - } - public static org.bukkit.material.Lever makeLeverWithData(byte data) { return new org.bukkit.material.Lever(Material.LEVER, data); } - public static int getTypeId_Block(Block block) - { - return block.getTypeId(); - } - public static String getName_EntityType(EntityType et) { return et.getName(); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 5a3272978..c74059e93 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -24,6 +24,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -400,4 +401,22 @@ public static String getNmsVersion() return packageName.substring(packageName.lastIndexOf('.') + 1); } + public static final List WOOL_COLORS = Arrays.asList( + Material.WHITE_WOOL, + Material.RED_WOOL, + Material.ORANGE_WOOL, + Material.YELLOW_WOOL, + Material.GREEN_WOOL, + Material.LIME_WOOL, + Material.LIGHT_BLUE_WOOL, + Material.CYAN_WOOL, + Material.BLUE_WOOL, + Material.PURPLE_WOOL, + Material.MAGENTA_WOOL, + Material.PINK_WOOL, + Material.BROWN_WOOL, + Material.GRAY_WOOL, + Material.LIGHT_GRAY_WOOL, + Material.BLACK_WOOL); + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java b/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java index 671e5a1fe..a396a0758 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java @@ -68,7 +68,7 @@ protected World generateWorld() world.setSpawnLocation(0, 50, 0); final Block welcomeSignBlock = world.getBlockAt(0, 50, 0); - welcomeSignBlock.setType(Material.SIGN_POST); + welcomeSignBlock.setType(Material.SIGN); org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState(); org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java deleted file mode 100644 index 4fed4c73d..000000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomBlockPopulator.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Cleanroom Generator - * Copyright (C) 2011-2012 nvx - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package me.totalfreedom.totalfreedommod.world; - -import java.util.Random; -import org.bukkit.Chunk; -import org.bukkit.World; -import org.bukkit.generator.BlockPopulator; - -@SuppressWarnings("deprecation") -public class CleanroomBlockPopulator extends BlockPopulator -{ - - byte[] layerDataValues; - - protected CleanroomBlockPopulator(byte[] layerDataValues) - { - this.layerDataValues = layerDataValues; - } - - @Override - public void populate(World world, Random random, Chunk chunk) - { - if (layerDataValues != null) - { - int x = chunk.getX() << 4; - int z = chunk.getZ() << 4; - - for (int y = 0; y < layerDataValues.length; y++) - { - byte dataValue = layerDataValues[y]; - if (dataValue == 0) - { - continue; - } - for (int xx = 0; xx < 16; xx++) - { - for (int zz = 0; zz < 16; zz++) - { - world.getBlockAt(x + xx, y, z + zz).setData(dataValue); - } - } - } - } - } -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java index 21bad0770..04641fecd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java @@ -15,208 +15,125 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + package me.totalfreedom.totalfreedommod.world; -import static java.lang.System.arraycopy; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; -import java.util.logging.Logger; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; -@SuppressWarnings("deprecation") +import java.util.Arrays; +import java.util.Random; +import java.util.logging.Logger; + +import static java.lang.System.arraycopy; + public class CleanroomChunkGenerator extends ChunkGenerator { + private Logger log = Logger.getLogger("Minecraft"); - private static final Logger log = Bukkit.getLogger(); - private short[] layer; - private byte[] layerDataValues; + private Material[] materials; public CleanroomChunkGenerator() { this("64,stone"); } - public CleanroomChunkGenerator(String id) - { - if (id != null) - { - try - { + public CleanroomChunkGenerator(String id) { + if (id != null) { + try { int y = 0; - layer = new short[128]; // Default to 128, will be resized later if required - layerDataValues = null; + materials = new Material[128]; // Default to 128, will be resized later if required - if ((id.length() > 0) && (id.charAt(0) == '.')) // Is the first character a '.'? If so, skip bedrock generation. - { + if ((id.length() > 0) && (id.charAt(0) == '.')) { + // Is the first character a '.'? If so, skip bedrock generation. id = id.substring(1); // Skip bedrock then and remove the . - } - else // Guess not, bedrock at layer0 it is then. - { - layer[y++] = (short) Material.BEDROCK.getId(); + } else { + // Guess not, bedrock at layer0 it is then. + materials[y++] = Material.BEDROCK; } - if (id.length() > 0) - { + if (id.length() > 0) { String tokens[] = id.split("[,]"); - if ((tokens.length % 2) != 0) - { - throw new Exception(); - } + if ((tokens.length % 2) != 0) throw new Exception(); - for (int i = 0; i < tokens.length; i += 2) - { + for (int i = 0; i < tokens.length; i += 2) { int height = Integer.parseInt(tokens[i]); - if (height <= 0) - { + if (height <= 0) { log.warning("[CleanroomGenerator] Invalid height '" + tokens[i] + "'. Using 64 instead."); height = 64; } String materialTokens[] = tokens[i + 1].split("[:]", 2); - byte dataValue = 0; - if (materialTokens.length == 2) - { - try - { - // Lets try to read the data value - dataValue = Byte.parseByte(materialTokens[1]); - } - catch (Exception e) - { - log.warning("[CleanroomGenerator] Invalid Data Value '" + materialTokens[1] + "'. Defaulting to 0."); - dataValue = 0; - } + + if (materialTokens.length == 2) { + log.warning("[CleanroomGenerator] Data values are no longer supported in 1.13. Defaulting to the base material for " + materialTokens[0]); } + Material mat = Material.matchMaterial(materialTokens[0]); - if (mat == null) - { - try - { - // Mabe it's an integer? - mat = Material.getMaterial(Integer.parseInt(materialTokens[0])); - } - catch (Exception e) - { - // Well, I guess it wasn't an integer after all... Awkward... - } - - if (mat == null) - { - log.warning("[CleanroomGenerator] Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone."); - mat = Material.STONE; - } + if (mat == null) { + log.warning("[CleanroomGenerator] Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone. (Integer IDs were removed in 1.13)"); + mat = Material.STONE; } - if (!mat.isBlock()) - { + if (!mat.isBlock()) { log.warning("[CleanroomGenerator] Error, '" + materialTokens[0] + "' is not a block. Defaulting to stone."); mat = Material.STONE; } - if (y + height > layer.length) - { - short[] newLayer = new short[Math.max(y + height, layer.length * 2)]; - arraycopy(layer, 0, newLayer, 0, y); - layer = newLayer; - if (layerDataValues != null) - { - byte[] newLayerDataValues = new byte[Math.max(y + height, layerDataValues.length * 2)]; - arraycopy(layerDataValues, 0, newLayerDataValues, 0, y); - layerDataValues = newLayerDataValues; - } - } + if (y + height > materials.length) { + Material[] newMaterials = new Material[Math.max(y + height, materials.length * 2)]; - Arrays.fill(layer, y, y + height, (short) mat.getId()); - if (dataValue != 0) - { - if (layerDataValues == null) - { - layerDataValues = new byte[layer.length]; - } - Arrays.fill(layerDataValues, y, y + height, dataValue); + arraycopy(materials, 0, newMaterials, 0, y); + materials = newMaterials; } + + Arrays.fill(materials, y, y + height, mat); y += height; } } // Trim to size - if (layer.length > y) - { - short[] newLayer = new short[y]; - arraycopy(layer, 0, newLayer, 0, y); - layer = newLayer; + if (materials.length > y) { + Material[] newMaterials = new Material[y]; + arraycopy(materials, 0, newMaterials, 0, y); + materials = newMaterials; } - if (layerDataValues != null && layerDataValues.length > y) - { - byte[] newLayerDataValues = new byte[y]; - arraycopy(layerDataValues, 0, newLayerDataValues, 0, y); - layerDataValues = newLayerDataValues; - } - } - catch (Exception e) - { + } catch (Exception e) { log.severe("[CleanroomGenerator] Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e.toString()); e.printStackTrace(); - layerDataValues = null; - layer = new short[65]; - layer[0] = (short) Material.BEDROCK.getId(); - Arrays.fill(layer, 1, 65, (short) Material.STONE.getId()); + + materials = new Material[65]; + materials[0] = Material.BEDROCK; + Arrays.fill(materials, 1, 65, Material.STONE); } - } - else - { - layerDataValues = null; - layer = new short[65]; - layer[0] = (short) Material.BEDROCK.getId(); - Arrays.fill(layer, 1, 65, (short) Material.STONE.getId()); + } else { + materials = new Material[65]; + materials[0] = Material.BEDROCK; + Arrays.fill(materials, 1, 65, Material.STONE); } } @Override - public short[][] generateExtBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) - { + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { int maxHeight = world.getMaxHeight(); - if (layer.length > maxHeight) - { - log.warning("[CleanroomGenerator] Error, chunk height " + layer.length + " is greater than the world max height (" + maxHeight + "). Trimming to world max height."); - short[] newLayer = new short[maxHeight]; - arraycopy(layer, 0, newLayer, 0, maxHeight); - layer = newLayer; - } - short[][] result = new short[maxHeight / 16][]; // 16x16x16 chunks - for (int i = 0; i < layer.length; i += 16) - { - result[i >> 4] = new short[4096]; - for (int y = 0; y < Math.min(16, layer.length - i); y++) - { - Arrays.fill(result[i >> 4], y * 16 * 16, (y + 1) * 16 * 16, layer[i + y]); - } + if (materials.length > maxHeight) { + log.warning("[CleanroomGenerator] Error, chunk height " + materials.length + " is greater than the world max height (" + maxHeight + "). Trimming to world max height."); + Material[] newMaterials = new Material[maxHeight]; + arraycopy(materials, 0, newMaterials, 0, maxHeight); + materials = newMaterials; } - return result; - } + ChunkData result = createChunkData(world); - @Override - public List getDefaultPopulators(World world) - { - if (layerDataValues != null) - { - return Arrays.asList((BlockPopulator) new CleanroomBlockPopulator(layerDataValues)); - } - else - { - // This is the default, but just in case default populators change to stock minecraft populators by default... - return new ArrayList<>(); + for (int i = 0; i < materials.length; i++) { + result.setRegion(0, i, 0, 15, i, 15, materials[i]); } + + return result; } @Override @@ -234,4 +151,4 @@ public Location getFixedSpawnLocation(World world, Random random) return new Location(world, 0, world.getHighestBlockYAt(0, 0), 0); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java b/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java index 6d6601087..9b5955bbb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java @@ -3,7 +3,6 @@ import java.io.File; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -46,7 +45,7 @@ protected World generateWorld() world.setSpawnLocation(0, 50, 0); final Block welcomeSignBlock = world.getBlockAt(0, 50, 0); - welcomeSignBlock.setType(Material.SIGN_POST); + welcomeSignBlock.setType(Material.SIGN); org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState(); org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index cebffe6aa..1ca018684 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,7 @@ name: TotalFreedomMod main: me.totalfreedom.totalfreedommod.TotalFreedomMod version: ${tfm.build.version} +api-version: 1.13 description: Plugin for the Total Freedom server. depend: [Aero, WorldEdit] softdepend: [BukkitTelnet, Essentials, LibsDisguises] From 239b637d2a12c209310495c0523e3566d3a65a8c Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Sat, 23 Feb 2019 00:02:19 +0100 Subject: [PATCH 02/15] Removed old metrics and added BStats. Resolves #2172 --- pom.xml | 36 + .../totalfreedommod/TotalFreedomMod.java | 14 +- src/main/java/org/mcstats/Metrics.java | 852 ------------------ 3 files changed, 39 insertions(+), 863 deletions(-) delete mode 100644 src/main/java/org/mcstats/Metrics.java diff --git a/pom.xml b/pom.xml index f800c25c4..87deae97d 100644 --- a/pom.xml +++ b/pom.xml @@ -59,6 +59,10 @@ sk89q-snapshots http://maven.sk89q.com/artifactory/repo + + CodeMC + https://repo.codemc.org/repository/maven-public + @@ -116,6 +120,13 @@ worldedit-core 6.1.0-TF + + + org.bstats + bstats-bukkit + 1.4 + compile + @@ -303,6 +314,31 @@ + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + + + org.bstats + me.totalfreedom.totalfreedommod + + + + + + package + + shade + + + + diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 04011fc16..d209736c4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -39,7 +39,7 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; -import org.mcstats.Metrics; +import org.bstats.bukkit.Metrics; public class TotalFreedomMod extends AeroPlugin { @@ -210,16 +210,8 @@ public void enable() timer.update(); FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms"); - // Metrics @ http://mcstats.org/plugin/TotalFreedomMod - try - { - final Metrics metrics = new Metrics(plugin); - metrics.start(); - } - catch (IOException ex) - { - FLog.warning("Failed to submit metrics data: " + ex.getMessage()); - } + //BStats Metrics + Metrics metrics = new Metrics(this); // Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438 new BukkitRunnable() diff --git a/src/main/java/org/mcstats/Metrics.java b/src/main/java/org/mcstats/Metrics.java deleted file mode 100644 index 74deca20f..000000000 --- a/src/main/java/org/mcstats/Metrics.java +++ /dev/null @@ -1,852 +0,0 @@ -/* - * Copyright 2011-2013 Tyler Blair. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and contributors and should not be interpreted as representing official policies, - * either expressed or implied, of anybody else. - */ -package org.mcstats; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.UUID; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; -import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.scheduler.BukkitTask; - -public class Metrics -{ - - /** - * The current revision number - */ - private final static int REVISION = 7; - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://report.mcstats.org"; - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/plugin/TotalFreedomMod"; // TotalFreedomMod - /** - * Interval of time to ping (in minutes) - */ - private static final int PING_INTERVAL = 15; - /** - * The plugin this metrics submits for - */ - private final Plugin plugin; - /** - * All of the custom graphs to submit to metrics - */ - private final Set graphs = Collections.synchronizedSet(new HashSet()); - /** - * The plugin configuration file - */ - private final YamlConfiguration configuration; - /** - * The plugin configuration file - */ - private final File configurationFile; - /** - * Unique server id - */ - private final String guid; - /** - * Debug mode - */ - private final boolean debug; - /** - * Lock for synchronization - */ - private final Object optOutLock = new Object(); - /** - * The scheduled task - */ - private volatile BukkitTask task = null; - - public Metrics(final Plugin plugin) throws IOException - { - if (plugin == null) - { - throw new IllegalArgumentException("Plugin cannot be null"); - } - - this.plugin = plugin; - - // load the config - configurationFile = getConfigFile(); - configuration = YamlConfiguration.loadConfiguration(configurationFile); - - // add some defaults - configuration.addDefault("opt-out", false); - configuration.addDefault("guid", UUID.randomUUID().toString()); - configuration.addDefault("debug", false); - - // Do we need to create the file? - if (configuration.get("guid", null) == null) - { - configuration.options().header("http://mcstats.org").copyDefaults(true); - configuration.save(configurationFile); - } - - // Load the guid then - guid = configuration.getString("guid"); - debug = configuration.getBoolean("debug", false); - } - - /** - * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics website. Plotters can be added to the graph object returned. - * - * @param name The name of the graph - * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given - */ - public Graph createGraph(final String name) - { - if (name == null) - { - throw new IllegalArgumentException("Graph name cannot be null"); - } - - // Construct the graph object - final Graph graph = new Graph(name); - - // Now we can add our graph - graphs.add(graph); - - // and return back - return graph; - } - - /** - * Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend - * - * @param graph The name of the graph - */ - public void addGraph(final Graph graph) - { - if (graph == null) - { - throw new IllegalArgumentException("Graph cannot be null"); - } - - graphs.add(graph); - } - - /** - * Start measuring statistics. This will immediately create an async repeating task as the plugin and send the initial data to the metrics backend, and then after that it will post in increments - * of PING_INTERVAL * 1200 ticks. - * - * @return True if statistics measuring is running, otherwise false. - */ - public boolean start() - { - synchronized (optOutLock) - { - // Did we opt out? - if (isOptOut()) - { - return false; - } - - // Is metrics already running? - if (task != null) - { - return true; - } - - // Begin hitting the server with glorious data - task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() - { - private boolean firstPost = true; - - @Override - public void run() - { - try - { - // This has to be synchronized or it can collide with the disable method. - synchronized (optOutLock) - { - // Disable Task, if it is running and the server owner decided to opt-out - if (isOptOut() && task != null) - { - task.cancel(); - task = null; - // Tell all plotters to stop gathering information. - for (Graph graph : graphs) - { - graph.onOptOut(); - } - } - } - - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin(!firstPost); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } - catch (IOException e) - { - if (debug) - { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); - } - } - } - }, 0, PING_INTERVAL * 1200); - - return true; - } - } - - /** - * Has the server owner denied plugin metrics? - * - * @return true if metrics should be opted out of it - */ - public boolean isOptOut() - { - synchronized (optOutLock) - { - try - { - // Reload the metrics file - configuration.load(getConfigFile()); - } - catch (IOException ex) - { - if (debug) - { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - return true; - } - catch (InvalidConfigurationException ex) - { - if (debug) - { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - return true; - } - return configuration.getBoolean("opt-out", false); - } - } - - /** - * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. - * - * @throws java.io.IOException - */ - public void enable() throws IOException - { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) - { - // Check if the server owner has already set opt-out, if not, set it. - if (isOptOut()) - { - configuration.set("opt-out", false); - configuration.save(configurationFile); - } - - // Enable Task, if it is not running - if (task == null) - { - start(); - } - } - } - - /** - * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. - * - * @throws java.io.IOException - */ - public void disable() throws IOException - { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) - { - // Check if the server owner has already set opt-out, if not, set it. - if (!isOptOut()) - { - configuration.set("opt-out", true); - configuration.save(configurationFile); - } - - // Disable Task, if it is running - if (task != null) - { - task.cancel(); - task = null; - } - } - } - - /** - * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status - * - * @return the File object for the config file - */ - public File getConfigFile() - { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use - // is to abuse the plugin object we already have - // plugin.getDataFolder() => base/plugins/PluginA/ - // pluginsFolder => base/plugins/ - // The base is not necessarily relative to the startup directory. - File pluginsFolder = plugin.getDataFolder().getParentFile(); - - // return => base/plugins/PluginMetrics/config.yml - return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); - } - - /** - * Generic method that posts a plugin to the metrics website - */ - private void postPlugin(final boolean isPing) throws IOException - { - // Server software specific section - PluginDescriptionFile description = plugin.getDescription(); - String pluginName = description.getName(); - boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled - String pluginVersion = description.getVersion(); - String serverVersion = Bukkit.getVersion(); - int playersOnline = Bukkit.getServer().getOnlinePlayers().size(); - - // END server software specific section -- all code below does not use any code outside of this class / Java - // Construct the post data - StringBuilder json = new StringBuilder(1024); - json.append('{'); - - // The plugin's description file containg all of the plugin data such as name, version, author, etc - appendJSONPair(json, "guid", guid); - appendJSONPair(json, "plugin_version", pluginVersion); - appendJSONPair(json, "server_version", serverVersion); - appendJSONPair(json, "players_online", Integer.toString(playersOnline)); - - // New data as of R6 - String osname = System.getProperty("os.name"); - String osarch = System.getProperty("os.arch"); - String osversion = System.getProperty("os.version"); - String java_version = System.getProperty("java.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - // normalize os arch .. amd64 -> x86_64 - if (osarch.equals("amd64")) - { - osarch = "x86_64"; - } - - appendJSONPair(json, "osname", osname); - appendJSONPair(json, "osarch", osarch); - appendJSONPair(json, "osversion", osversion); - appendJSONPair(json, "cores", Integer.toString(coreCount)); - appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); - appendJSONPair(json, "java_version", java_version); - - // If we're pinging, append it - if (isPing) - { - appendJSONPair(json, "ping", "1"); - } - - if (graphs.size() > 0) - { - synchronized (graphs) - { - json.append(','); - json.append('"'); - json.append("graphs"); - json.append('"'); - json.append(':'); - json.append('{'); - - boolean firstGraph = true; - - final Iterator iter = graphs.iterator(); - - while (iter.hasNext()) - { - Graph graph = iter.next(); - - StringBuilder graphJson = new StringBuilder(); - graphJson.append('{'); - - for (Plotter plotter : graph.getPlotters()) - { - appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue())); - } - - graphJson.append('}'); - - if (!firstGraph) - { - json.append(','); - } - - json.append(escapeJSON(graph.getName())); - json.append(':'); - json.append(graphJson); - - firstGraph = false; - } - - json.append('}'); - } - } - - // close json - json.append('}'); - - // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName))); - - // Connect to the website - URLConnection connection; - - // Mineshafter creates a socks proxy, so we can safely bypass it - // It does not reroute POST requests so we need to go around it - if (isMineshafterPresent()) - { - connection = url.openConnection(Proxy.NO_PROXY); - } - else - { - connection = url.openConnection(); - } - - byte[] uncompressed = json.toString().getBytes(); - byte[] compressed = gzip(json.toString()); - - // Headers - connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); - connection.addRequestProperty("Content-Type", "application/json"); - connection.addRequestProperty("Content-Encoding", "gzip"); - connection.addRequestProperty("Content-Length", Integer.toString(compressed.length)); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - - connection.setDoOutput(true); - - if (debug) - { - System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length); - } - - // Write the data - OutputStream os = connection.getOutputStream(); - os.write(compressed); - os.flush(); - - // Now read the response - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String response = reader.readLine(); - - // close resources - os.close(); - reader.close(); - - if (response == null || response.startsWith("ERR") || response.startsWith("7")) - { - if (response == null) - { - response = "null"; - } - else if (response.startsWith("7")) - { - response = response.substring(response.startsWith("7,") ? 2 : 1); - } - - throw new IOException(response); - } - else - { - // Is this the first update this hour? - if (response.equals("1") || response.contains("This is your first update this hour")) - { - synchronized (graphs) - { - final Iterator iter = graphs.iterator(); - - while (iter.hasNext()) - { - final Graph graph = iter.next(); - - for (Plotter plotter : graph.getPlotters()) - { - plotter.reset(); - } - } - } - } - } - } - - /** - * GZip compress a string of bytes - * - * @param input - * @return - */ - public static byte[] gzip(String input) - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzos = null; - - try - { - gzos = new GZIPOutputStream(baos); - gzos.write(input.getBytes("UTF-8")); - } - catch (IOException e) - { - e.printStackTrace(); - } - finally - { - if (gzos != null) - { - try - { - gzos.close(); - } - catch (IOException ignore) - { - } - } - } - - return baos.toByteArray(); - } - - /** - * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return true if mineshafter is installed on the server - */ - private boolean isMineshafterPresent() - { - try - { - Class.forName("mineshafter.MineServer"); - return true; - } - catch (Exception e) - { - return false; - } - } - - /** - * Appends a json encoded key/value pair to the given string builder. - * - * @param json - * @param key - * @param value - * @throws UnsupportedEncodingException - */ - private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException - { - boolean isValueNumeric = false; - - try - { - if (value.equals("0") || !value.endsWith("0")) - { - Double.parseDouble(value); - isValueNumeric = true; - } - } - catch (NumberFormatException e) - { - isValueNumeric = false; - } - - if (json.charAt(json.length() - 1) != '{') - { - json.append(','); - } - - json.append(escapeJSON(key)); - json.append(':'); - - if (isValueNumeric) - { - json.append(value); - } - else - { - json.append(escapeJSON(value)); - } - } - - /** - * Escape a string to create a valid JSON string - * - * @param text - * @return - */ - private static String escapeJSON(String text) - { - StringBuilder builder = new StringBuilder(); - - builder.append('"'); - for (int index = 0; index < text.length(); index++) - { - char chr = text.charAt(index); - - switch (chr) - { - case '"': - case '\\': - builder.append('\\'); - builder.append(chr); - break; - case '\b': - builder.append("\\b"); - break; - case '\t': - builder.append("\\t"); - break; - case '\n': - builder.append("\\n"); - break; - case '\r': - builder.append("\\r"); - break; - default: - if (chr < ' ') - { - String t = "000" + Integer.toHexString(chr); - builder.append("\\u" + t.substring(t.length() - 4)); - } - else - { - builder.append(chr); - } - break; - } - } - builder.append('"'); - - return builder.toString(); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String urlEncode(final String text) throws UnsupportedEncodingException - { - return URLEncoder.encode(text, "UTF-8"); - } - - /** - * Represents a custom graph on the website - */ - public static class Graph - { - - /** - * The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is rejected - */ - private final String name; - /** - * The set of plotters that are contained within this graph - */ - private final Set plotters = new LinkedHashSet<>(); - - private Graph(final String name) - { - this.name = name; - } - - /** - * Gets the graph's name - * - * @return the Graph's name - */ - public String getName() - { - return name; - } - - /** - * Add a plotter to the graph, which will be used to plot entries - * - * @param plotter the plotter to add to the graph - */ - public void addPlotter(final Plotter plotter) - { - plotters.add(plotter); - } - - /** - * Remove a plotter from the graph - * - * @param plotter the plotter to remove from the graph - */ - public void removePlotter(final Plotter plotter) - { - plotters.remove(plotter); - } - - /** - * Gets an unmodifiable set of the plotter objects in the graph - * - * @return an unmodifiable {@link java.util.Set} of the plotter objects - */ - public Set getPlotters() - { - return Collections.unmodifiableSet(plotters); - } - - @Override - public int hashCode() - { - return name.hashCode(); - } - - @Override - public boolean equals(final Object object) - { - if (!(object instanceof Graph)) - { - return false; - } - - final Graph graph = (Graph) object; - return graph.name.equals(name); - } - - /** - * Called when the server owner decides to opt-out of BukkitMetrics while the server is running. - */ - protected void onOptOut() - { - } - } - - /** - * Interface used to collect custom data for a plugin - */ - public static abstract class Plotter - { - - /** - * The plot's name - */ - private final String name; - - /** - * Construct a plotter with the default plot name - */ - public Plotter() - { - this("Default"); - } - - /** - * Construct a plotter with a specific plot name - * - * @param name the name of the plotter to use, which will show up on the website - */ - public Plotter(final String name) - { - this.name = name; - } - - /** - * Get the current value for the plotted point. Since this function defers to an external function it may or may not return immediately thus cannot be guaranteed to be thread friendly or safe. - * This function can be called from any thread so care should be taken when accessing resources that need to be synchronized. - * - * @return the current value for the point to be plotted. - */ - public abstract int getValue(); - - /** - * Get the column name for the plotted point - * - * @return the plotted point's column name - */ - public String getColumnName() - { - return name; - } - - /** - * Called after the website graphs have been updated - */ - public void reset() - { - } - - @Override - public int hashCode() - { - return getColumnName().hashCode(); - } - - @Override - public boolean equals(final Object object) - { - if (!(object instanceof Plotter)) - { - return false; - } - - final Plotter plotter = (Plotter) object; - return plotter.name.equals(name) && plotter.getValue() == getValue(); - } - } - -} From 13ca59c7d54cc0fd28458c3b63da47dc20eb9737 Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Sun, 3 Mar 2019 22:14:57 +0100 Subject: [PATCH 03/15] Fixed the issue with the tax syntax as per #1768 and removed the original hard coded blocked tag list and moved to the config file --- .../totalfreedommod/command/Command_tag.java | 13 +++++++------ .../totalfreedommod/config/ConfigEntry.java | 1 + src/main/resources/config.yml | 9 ++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index 085cbae9f..eadfc0fed 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -1,7 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Arrays; +import com.google.common.collect.Lists; +import java.util.Collection; import java.util.List; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -12,18 +14,17 @@ import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.BOTH) -@CommandParameters(description = "Sets yourself a prefix", usage = "/ | off | clear | clearall>") +@CommandParameters(description = "Sets yourself a prefix", usage = "/ | off | clear | clearall | list>") public class Command_tag extends FreedomCommand { - public static final List FORBIDDEN_WORDS = Arrays.asList(new String[] - { - "admin", "owner", "moderator", "developer", "console" - }); + public static final List FORBIDDEN_WORDS = Lists.newArrayList(); @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + FORBIDDEN_WORDS.addAll((Collection) ConfigEntry.BLOCKED_TAGS.getList()); + if (args.length == 1) { if ("list".equalsIgnoreCase(args[0])) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 01fa9ed8a..08c99163f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -83,6 +83,7 @@ public enum ConfigEntry FAMOUS_PLAYERS(List.class, "famous_players"), OVERLORD_IPS(List.class, "overlord_ips"), NOADMIN_IPS(List.class, "noadmin_ips"), + BLOCKED_TAGS(List.class, "blocked_tags"), ADMIN_ONLY_MODE(Boolean.class, "admin_only_mode"), AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"); // diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8c0bddb0a..52e33817f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -336,4 +336,11 @@ overlord_ips: - 107.191.101.27 - 178.62.117.94 - 141.101.104.243 - + +# Tags that may not be set by players +blocked_tags: + - admin + - moderator + - owner + - developer + - console \ No newline at end of file From 28e4cf9797fbdadc7f312806b667cbd27509526d Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Mon, 4 Mar 2019 22:07:38 +0000 Subject: [PATCH 04/15] Worked to make TFM build properly in IntelliJ due to unstable Netbeans versions and look to have also fixed the issue with BStats --- .gitignore | 3 +- .idea/compiler.xml | 16 + .idea/encodings.xml | 6 + .idea/misc.xml | 13 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 425 ++++++++++++++++++ pom.xml | 63 +-- .../totalfreedommod/ServerInterface.java | 2 +- .../totalfreedommod/TotalFreedomMod.java | 1 - 10 files changed, 510 insertions(+), 33 deletions(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index 55aa63618..a570db5e6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,8 @@ manifest.mf *.iml *.ipr *.iws -/.idea +/.idea/libraries/* +/.idea/artifacts/* # Maven excludes /target diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..ddcb0e539 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..e79da7ece --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..ab4c8a3fe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..8915fc5f8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..999af049e --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,425 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1551720253060 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TotalFreedomMod:jar + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + totalfreedom + + + + + + + + 11 + + + + + + + + Maven: com.github.Pravian:Aero:a0e1dc5 + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8bd8ad980..869da67fb 100644 --- a/pom.xml +++ b/pom.xml @@ -98,12 +98,6 @@ 2.5 - - org.projectlombok - lombok - 1.16.16 - - org.spigotmc spigot-api @@ -150,6 +144,12 @@ compile + + org.projectlombok + lombok + 1.16.16 + + @@ -162,6 +162,32 @@ + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + + + org.bstats + me.totalfreedom.totalfreedommod.util + + + + + + package + + shade + + + + + org.apache.maven.plugins @@ -335,30 +361,7 @@ - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.0 - - - - - org.bstats - me.totalfreedom.totalfreedommod - - - - - - package - - shade - - - - + diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java index 117eda500..840ebf1c5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java @@ -6,7 +6,7 @@ public class ServerInterface extends FreedomService { - public static final String COMPILE_NMS_VERSION = "v1_13_R1"; + public static final String COMPILE_NMS_VERSION = "v1_13_R2"; public ServerInterface(TotalFreedomMod plugin) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index d209736c4..05b21ba9e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -2,7 +2,6 @@ import me.totalfreedom.totalfreedommod.fun.Trailer; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.util.Properties; import me.totalfreedom.totalfreedommod.admin.AdminList; From 4ce62c30cb7475e1343f5ce67e954b1d980e6d66 Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Tue, 5 Mar 2019 12:14:05 +0000 Subject: [PATCH 05/15] Updates to the .gitignore to remove the workspace file --- .gitignore | 4 +- .idea/workspace.xml | 425 -------------------------------------------- 2 files changed, 2 insertions(+), 427 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index a570db5e6..f76783f38 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,6 @@ git.properties /dist /build manifest.mf -# Now defines that Maven CheckStyle is used -# nb-configuration.xml # Eclipse excludes .project @@ -23,9 +21,11 @@ manifest.mf *.iws /.idea/libraries/* /.idea/artifacts/* +.idea/workspace.xml # Maven excludes /target +dependency-reduced-pom.xml # OS generated files .DS_Store diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 999af049e..000000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,425 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1551720253060 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TotalFreedomMod:jar - - - - - - - - No facets are configured - - - - - - - - - - - - - - - 1.8 - - - - - - - - totalfreedom - - - - - - - - 11 - - - - - - - - Maven: com.github.Pravian:Aero:a0e1dc5 - - - - - - - - \ No newline at end of file From af1c82055475cba67f9e510c0be4ce1273ab67c1 Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Tue, 5 Mar 2019 13:05:18 +0000 Subject: [PATCH 06/15] Scrapped original way of doing the Metrics and moved the metrics system into TFM for #2172 --- pom.xml | 37 - .../totalfreedommod/TotalFreedomMod.java | 3 +- .../totalfreedommod/util/Metrics.java | 695 ++++++++++++++++++ 3 files changed, 697 insertions(+), 38 deletions(-) create mode 100755 src/main/java/me/totalfreedom/totalfreedommod/util/Metrics.java diff --git a/pom.xml b/pom.xml index 869da67fb..e63d0772e 100644 --- a/pom.xml +++ b/pom.xml @@ -79,10 +79,6 @@ true - - CodeMC - https://repo.codemc.org/repository/maven-public - @@ -136,13 +132,6 @@ worldedit-core 7.0.0-TF-SNAPSHOT-R0.2 - - - org.bstats - bstats-bukkit - 1.4 - compile - org.projectlombok @@ -162,32 +151,6 @@ - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.0 - - - - - org.bstats - me.totalfreedom.totalfreedommod.util - - - - - - package - - shade - - - - - org.apache.maven.plugins diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 05b21ba9e..db4b2afe6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -32,13 +32,14 @@ import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.MethodTimer; +import me.totalfreedom.totalfreedommod.util.Metrics; import me.totalfreedom.totalfreedommod.world.WorldManager; import net.pravian.aero.component.service.ServiceManager; import net.pravian.aero.plugin.AeroPlugin; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; -import org.bstats.bukkit.Metrics; + public class TotalFreedomMod extends AeroPlugin { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/Metrics.java b/src/main/java/me/totalfreedom/totalfreedommod/util/Metrics.java new file mode 100755 index 000000000..4c3b1e725 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/Metrics.java @@ -0,0 +1,695 @@ +package me.totalfreedom.totalfreedommod.util; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.ServicePriority; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import javax.net.ssl.HttpsURLConnection; +import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.zip.GZIPOutputStream; + +/** + * bStats collects some data for plugin authors. + *

+ * Check out https://bStats.org/ to learn more about bStats! + */ +@SuppressWarnings({"WeakerAccess", "unused"}) +public class Metrics { + + static { + // You can use the property to disable the check in your test environment + if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { + // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D + final String defaultPackage = new String( + new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'}); + final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); + // We want to make sure nobody just copy & pastes the example and use the wrong package names + if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) { + throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); + } + } + } + + // The version of this bStats class + public static final int B_STATS_VERSION = 1; + + // The url to which the data is sent + private static final String URL = "https://bStats.org/submitData/bukkit"; + + // Is bStats enabled on this server? + private boolean enabled; + + // Should failed requests be logged? + private static boolean logFailedRequests; + + // Should the sent data be logged? + private static boolean logSentData; + + // Should the response text be logged? + private static boolean logResponseStatusText; + + // The uuid of the server + private static String serverUUID; + + // The plugin + private final Plugin plugin; + + // A list with all custom charts + private final List charts = new ArrayList<>(); + + /** + * Class constructor. + * + * @param plugin The plugin which stats should be submitted. + */ + public Metrics(Plugin plugin) { + if (plugin == null) { + throw new IllegalArgumentException("Plugin cannot be null!"); + } + this.plugin = plugin; + + // Get the config file + File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + File configFile = new File(bStatsFolder, "config.yml"); + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + + // Check if the config file exists + if (!config.isSet("serverUuid")) { + + // Add default values + config.addDefault("enabled", true); + // Every server gets it's unique random id. + config.addDefault("serverUuid", UUID.randomUUID().toString()); + // Should failed request be logged? + config.addDefault("logFailedRequests", false); + // Should the sent data be logged? + config.addDefault("logSentData", false); + // Should the response text be logged? + config.addDefault("logResponseStatusText", false); + + // Inform the server owners about bStats + config.options().header( + "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + + "To honor their work, you should not disable it.\n" + + "This has nearly no effect on the server performance!\n" + + "Check out https://bStats.org/ to learn more :)" + ).copyDefaults(true); + try { + config.save(configFile); + } catch (IOException ignored) { } + } + + // Load the data + enabled = config.getBoolean("enabled", true); + serverUUID = config.getString("serverUuid"); + logFailedRequests = config.getBoolean("logFailedRequests", false); + logSentData = config.getBoolean("logSentData", false); + logResponseStatusText = config.getBoolean("logResponseStatusText", false); + + if (enabled) { + boolean found = false; + // Search for all other bStats Metrics classes to see if we are the first one + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + found = true; // We aren't the first + break; + } catch (NoSuchFieldException ignored) { } + } + // Register our service + Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); + if (!found) { + // We are the first! + startSubmitting(); + } + } + } + + /** + * Checks if bStats is enabled. + * + * @return Whether bStats is enabled or not. + */ + public boolean isEnabled() { + return enabled; + } + + /** + * Adds a custom chart. + * + * @param chart The chart to add. + */ + public void addCustomChart(CustomChart chart) { + if (chart == null) { + throw new IllegalArgumentException("Chart cannot be null!"); + } + charts.add(chart); + } + + /** + * Starts the Scheduler which submits our data every 30 minutes. + */ + private void startSubmitting() { + final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if (!plugin.isEnabled()) { // Plugin was disabled + timer.cancel(); + return; + } + // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler + // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) + Bukkit.getScheduler().runTask(plugin, () -> submitData()); + } + }, 1000 * 60 * 5, 1000 * 60 * 30); + // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start + // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! + // WARNING: Just don't do it! + } + + /** + * Gets the plugin specific data. + * This method is called using Reflection. + * + * @return The plugin specific data. + */ + public JSONObject getPluginData() { + JSONObject data = new JSONObject(); + + String pluginName = plugin.getDescription().getName(); + String pluginVersion = plugin.getDescription().getVersion(); + + data.put("pluginName", pluginName); // Append the name of the plugin + data.put("pluginVersion", pluginVersion); // Append the version of the plugin + JSONArray customCharts = new JSONArray(); + for (CustomChart customChart : charts) { + // Add the data of the custom charts + JSONObject chart = customChart.getRequestJsonObject(); + if (chart == null) { // If the chart is null, we skip it + continue; + } + customCharts.add(chart); + } + data.put("customCharts", customCharts); + + return data; + } + + /** + * Gets the server specific data. + * + * @return The server specific data. + */ + private JSONObject getServerData() { + // Minecraft specific data + int playerAmount; + try { + // Around MC 1.8 the return type was changed to a collection from an array, + // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; + Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) + ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() + : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; + } catch (Exception e) { + playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed + } + int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; + String bukkitVersion = Bukkit.getVersion(); + + // OS/Java specific data + String javaVersion = System.getProperty("java.version"); + String osName = System.getProperty("os.name"); + String osArch = System.getProperty("os.arch"); + String osVersion = System.getProperty("os.version"); + int coreCount = Runtime.getRuntime().availableProcessors(); + + JSONObject data = new JSONObject(); + + data.put("serverUUID", serverUUID); + + data.put("playerAmount", playerAmount); + data.put("onlineMode", onlineMode); + data.put("bukkitVersion", bukkitVersion); + + data.put("javaVersion", javaVersion); + data.put("osName", osName); + data.put("osArch", osArch); + data.put("osVersion", osVersion); + data.put("coreCount", coreCount); + + return data; + } + + /** + * Collects the data and sends it afterwards. + */ + private void submitData() { + final JSONObject data = getServerData(); + + JSONArray pluginData = new JSONArray(); + // Search for all other bStats Metrics classes to get their plugin data + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + + for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { + try { + pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider())); + } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } + } + } catch (NoSuchFieldException ignored) { } + } + + data.put("plugins", pluginData); + + // Create a new thread for the connection to the bStats server + new Thread(new Runnable() { + @Override + public void run() { + try { + // Send the data + sendData(plugin, data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); + } + } + } + }).start(); + } + + /** + * Sends the data to the bStats server. + * + * @param plugin Any plugin. It's just used to get a logger instance. + * @param data The data to send. + * @throws Exception If the request failed. + */ + private static void sendData(Plugin plugin, JSONObject data) throws Exception { + if (data == null) { + throw new IllegalArgumentException("Data cannot be null!"); + } + if (Bukkit.isPrimaryThread()) { + throw new IllegalAccessException("This method must not be called from the main thread!"); + } + if (logSentData) { + plugin.getLogger().info("Sending data to bStats: " + data.toString()); + } + HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); + + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + + // Add headers + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format + connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); + + // Send data + connection.setDoOutput(true); + DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); + outputStream.write(compressedData); + outputStream.flush(); + outputStream.close(); + + InputStream inputStream = connection.getInputStream(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + + StringBuilder builder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + bufferedReader.close(); + if (logResponseStatusText) { + plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString()); + } + } + + /** + * Gzips the given String. + * + * @param str The string to gzip. + * @return The gzipped String. + * @throws IOException If the compression failed. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + GZIPOutputStream gzip = new GZIPOutputStream(outputStream); + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + gzip.close(); + return outputStream.toByteArray(); + } + + /** + * Represents a custom chart. + */ + public static abstract class CustomChart { + + // The id of the chart + final String chartId; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + CustomChart(String chartId) { + if (chartId == null || chartId.isEmpty()) { + throw new IllegalArgumentException("ChartId cannot be null or empty!"); + } + this.chartId = chartId; + } + + private JSONObject getRequestJsonObject() { + JSONObject chart = new JSONObject(); + chart.put("chartId", chartId); + try { + JSONObject data = getChartData(); + if (data == null) { + // If the data is null we don't send the chart. + return null; + } + chart.put("data", data); + } catch (Throwable t) { + if (logFailedRequests) { + Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); + } + return null; + } + return chart; + } + + protected abstract JSONObject getChartData() throws Exception; + + } + + /** + * Represents a custom simple pie. + */ + public static class SimplePie extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimplePie(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + String value = callable.call(); + if (value == null || value.isEmpty()) { + // Null = skip the chart + return null; + } + data.put("value", value); + return data; + } + } + + /** + * Represents a custom advanced pie. + */ + public static class AdvancedPie extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedPie(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + continue; // Skip this invalid + } + allSkipped = false; + values.put(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + } + + /** + * Represents a custom drilldown pie. + */ + public static class DrilldownPie extends CustomChart { + + private final Callable>> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public DrilldownPie(String chartId, Callable>> callable) { + super(chartId); + this.callable = callable; + } + + @Override + public JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map> map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean reallyAllSkipped = true; + for (Map.Entry> entryValues : map.entrySet()) { + JSONObject value = new JSONObject(); + boolean allSkipped = true; + for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { + value.put(valueEntry.getKey(), valueEntry.getValue()); + allSkipped = false; + } + if (!allSkipped) { + reallyAllSkipped = false; + values.put(entryValues.getKey(), value); + } + } + if (reallyAllSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + } + + /** + * Represents a custom single line chart. + */ + public static class SingleLineChart extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SingleLineChart(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + int value = callable.call(); + if (value == 0) { + // Null = skip the chart + return null; + } + data.put("value", value); + return data; + } + + } + + /** + * Represents a custom multi line chart. + */ + public static class MultiLineChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public MultiLineChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + continue; // Skip this invalid + } + allSkipped = false; + values.put(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + + } + + /** + * Represents a custom simple bar chart. + */ + public static class SimpleBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimpleBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + for (Map.Entry entry : map.entrySet()) { + JSONArray categoryValues = new JSONArray(); + categoryValues.add(entry.getValue()); + values.put(entry.getKey(), categoryValues); + } + data.put("values", values); + return data; + } + + } + + /** + * Represents a custom advanced bar chart. + */ + public static class AdvancedBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().length == 0) { + continue; // Skip this invalid + } + allSkipped = false; + JSONArray categoryValues = new JSONArray(); + for (int categoryValue : entry.getValue()) { + categoryValues.add(categoryValue); + } + values.put(entry.getKey(), categoryValues); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + } + +} From 8fdd377af525e35becd9b1d4a6df3eb08cc5bdff Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Tue, 5 Mar 2019 15:57:37 +0000 Subject: [PATCH 07/15] Incremented Aero version to reflect current latest stable --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e63d0772e..cf27111ac 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ com.github.Pravian Aero - a0e1dc5 + 5f82926ab8 From 3452c1e04e733cedbbb54bef4fa5ae737e285336 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 23 Jun 2019 00:23:09 +0100 Subject: [PATCH 08/15] Updates from PR Feedback Added required new line. --- src/main/resources/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 52e33817f..51acc6e11 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -343,4 +343,5 @@ blocked_tags: - moderator - owner - developer - - console \ No newline at end of file + - console + From af850e61c7c7836785782c9750e9c5a815b4df5d Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Sun, 14 Jul 2019 23:21:15 +0100 Subject: [PATCH 09/15] Updated to reflect the current way we handle the forbidden usernames from being banned. --- .../totalfreedom/totalfreedommod/command/Command_tag.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index eadfc0fed..6885baaf8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -6,6 +6,7 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; @@ -18,12 +19,17 @@ public class Command_tag extends FreedomCommand { - public static final List FORBIDDEN_WORDS = Lists.newArrayList(); + private final List FORBIDDEN_WORDS = Lists.newArrayList(); @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + + // Load unbannable usernames + FORBIDDEN_WORDS.clear(); FORBIDDEN_WORDS.addAll((Collection) ConfigEntry.BLOCKED_TAGS.getList()); + FLog.info("Loaded " + FORBIDDEN_WORDS.size() + " forbidden tags."); + if (args.length == 1) { From c1c333eb5e4656bcc90df8c548683863a750113e Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Sun, 14 Jul 2019 23:27:18 +0100 Subject: [PATCH 10/15] Final updates to make this work... Whoops... --- .../me/totalfreedom/totalfreedommod/command/Command_tag.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index 6885baaf8..84c70dfdc 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -19,7 +19,7 @@ public class Command_tag extends FreedomCommand { - private final List FORBIDDEN_WORDS = Lists.newArrayList(); + public final List FORBIDDEN_WORDS = Lists.newArrayList(); @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) From bc722b3b7b05f37ce575397ee324386cfee47562 Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Sat, 14 Sep 2019 19:44:10 +0100 Subject: [PATCH 11/15] Fixes and improvements to the tag blocking process This should fix the memory leak I suspect. --- .../totalfreedommod/TotalFreedomMod.java | 4 ++ .../blocking/PlayerBlocker.java | 44 +++++++++++++++++++ .../totalfreedommod/command/Command_tag.java | 11 +---- .../command/Command_tagnyan.java | 3 +- 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index db4b2afe6..308ff1a22 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -13,6 +13,7 @@ import me.totalfreedom.totalfreedommod.blocking.MobBlocker; import me.totalfreedom.totalfreedommod.blocking.PotionBlocker; import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; +import me.totalfreedom.totalfreedommod.blocking.PlayerBlocker; import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge; import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge; @@ -97,6 +98,7 @@ public class TotalFreedomMod extends AeroPlugin public Jumppads jp; public Trailer tr; public HTTPDaemon hd; + public PlayerBlocker plb; // // Bridges public ServiceManager bridges; @@ -197,6 +199,8 @@ public void enable() // HTTPD hd = services.registerService(HTTPDaemon.class); + plb = services.registerService(PlayerBlocker.class); + // Start Services services.start(); // Start bridges diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java new file mode 100644 index 000000000..1a58dc004 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java @@ -0,0 +1,44 @@ +package me.totalfreedom.totalfreedommod.blocking; + +import com.google.common.collect.Lists; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; +import java.util.List; + +public class PlayerBlocker extends FreedomService +{ + + public static final List blockedTags = Lists.newArrayList(); + + public PlayerBlocker(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + // Load banned tags + blockedTags.clear(); + blockedTags.addAll((Collection) ConfigEntry.BLOCKED_TAGS.getList()); + FLog.info("Loaded " + blockedTags.size() + " banned tags."); + } + + @Override + protected void onStop() + { + } + +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index 84c70dfdc..1e5e2889a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -5,6 +5,7 @@ import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.blocking.PlayerBlocker; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -19,18 +20,10 @@ public class Command_tag extends FreedomCommand { - public final List FORBIDDEN_WORDS = Lists.newArrayList(); - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - // Load unbannable usernames - FORBIDDEN_WORDS.clear(); - FORBIDDEN_WORDS.addAll((Collection) ConfigEntry.BLOCKED_TAGS.getList()); - FLog.info("Loaded " + FORBIDDEN_WORDS.size() + " forbidden tags."); - - if (args.length == 1) { if ("list".equalsIgnoreCase(args[0])) @@ -138,7 +131,7 @@ else if ("set".equalsIgnoreCase(args[0])) return true; } - for (String word : FORBIDDEN_WORDS) + for (String word : PlayerBlocker.blockedTags) { if (rawTag.contains(word)) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java index 70eef7448..81859e4ae 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.blocking.PlayerBlocker; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -30,7 +31,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin } String tagStr = tag.toString(); - for (String word : Command_tag.FORBIDDEN_WORDS) + for (String word : PlayerBlocker.blockedTags) { if (tagStr.contains(word)) { From 0c5cafb14a4e88d8cff3aa535d98077b9cffe642 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 21 Sep 2019 21:05:07 +0100 Subject: [PATCH 12/15] Hopefully Fixing Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 41909c29d..f667def0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: java +dist: trusty jdk: - oraclejdk8 notifications: From 264f862eade3c84825e7c52f4be46879642102c0 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 21 Dec 2019 13:38:31 +0000 Subject: [PATCH 13/15] Moved to Essentials X in the hopes that will work properly --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cf27111ac..b47a8fd00 100644 --- a/pom.xml +++ b/pom.xml @@ -48,8 +48,8 @@ - ess-repo - http://repo.ess3.net/content/groups/essentials + ender-zone + https://ci.ender.zone/plugin/repository/ true From 5700d25d859be2c9a1dd668dd537aecd8c4a8f57 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 21 Dec 2019 13:41:02 +0000 Subject: [PATCH 14/15] Take 2 on fixing the repos --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b47a8fd00..38c16e010 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ ender-zone - https://ci.ender.zone/plugin/repository/ + https://ci.ender.zone/plugin/repository/everything/ true From ab0a38cd8df83395dd3f9d9d312902c81a9e3e5e Mon Sep 17 00:00:00 2001 From: Nathan Curran <30569566+Focusvity@users.noreply.github.com> Date: Mon, 23 Dec 2019 01:48:40 +1100 Subject: [PATCH 15/15] Fixed Essentials (#2183) --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 38c16e010..dd69d6c4b 100644 --- a/pom.xml +++ b/pom.xml @@ -115,8 +115,8 @@ net.ess3 - Essentials - 2.13.1 + EssentialsX + 2.16.0