From 7d0ea0837ec0ab3fc47098358e9f0919e66cb6c7 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sun, 18 Aug 2019 21:06:47 -0400 Subject: [PATCH] Fixes, added /hub, removed CONSOLE restrictions on some commands --- pom.xml | 4 +- .../totalfreedommod/ChatManager.java | 10 +- .../totalfreedommod/TotalFreedomMod.java | 3 + .../command/Command_adminmode.java | 2 +- .../totalfreedommod/command/Command_cuck.java | 6 +- .../command/Command_deafen.java | 2 +- .../totalfreedommod/command/Command_gtfo.java | 2 +- .../command/Command_hubworld.java | 203 ++++++++++++++++++ .../command/Command_kicknoob.java | 2 +- .../command/Command_opall.java | 18 -- .../command/Command_permban.java | 2 +- .../command/Command_radar.java | 113 ---------- .../command/Command_rawsay.java | 2 +- .../command/Command_saconfig.java | 11 +- .../command/Command_unban.java | 5 +- .../totalfreedommod/command/Command_vote.java | 34 +++ .../totalfreedommod/config/ConfigEntry.java | 1 + .../totalfreedommod/fun/ItemFun.java | 5 + .../hub/HubWorldRestrictions.java | 132 ++++++++++++ .../totalfreedommod/world/HubWorld.java | 99 +++++++++ .../totalfreedommod/world/WorldManager.java | 12 ++ src/main/resources/config.yml | 7 + 22 files changed, 523 insertions(+), 152 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/hub/HubWorldRestrictions.java create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/world/HubWorld.java diff --git a/pom.xml b/pom.xml index b8caf969..d99b1a55 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ me.totalfreedom totalfreedom - 5.2 + 6.0 jar UTF-8 - God + Smartn't ${project.name} ${maven.build.timestamp} MM/dd/yyyy HH:mm diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index 9856b06c..7cf2b99f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -120,6 +120,10 @@ public class ChatManager extends FreedomService { color = ChatColor.LIGHT_PURPLE; } + else if (color.equals(ChatColor.DARK_RED)) + { + color = ChatColor.BLUE; + } } return color; } @@ -138,6 +142,10 @@ public class ChatManager extends FreedomService { color = ChatColor.LIGHT_PURPLE; } + else if (color.equals(ChatColor.DARK_RED)) + { + color = ChatColor.BLUE; + } } return color + display.getAbbr(); } @@ -177,4 +185,4 @@ public class ChatManager extends FreedomService } } } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index b8fc765d..252d3710 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -39,6 +39,7 @@ import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder; import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilderList; import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilderWorldRestrictions; +import me.totalfreedom.totalfreedommod.hub.HubWorldRestrictions; import me.totalfreedom.totalfreedommod.player.PlayerList; import me.totalfreedom.totalfreedommod.playerverification.PlayerVerification; import me.totalfreedom.totalfreedommod.punishments.PunishmentList; @@ -125,6 +126,7 @@ public class TotalFreedomMod extends AeroPlugin public MasterBuilderWorldRestrictions mbwr; public SignBlocker snp; public PlayerVerification pv; + public HubWorldRestrictions hwr; // // Bridges public ServiceManager bridges; @@ -199,6 +201,7 @@ public class TotalFreedomMod extends AeroPlugin as = services.registerService(AntiSpam.class); mbl = services.registerService(MasterBuilderList.class); mbwr = services.registerService(MasterBuilderWorldRestrictions.class); + hwr = services.registerService(HubWorldRestrictions.class); pl = services.registerService(PlayerList.class); an = services.registerService(Announcer.class); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java index 83fc7046..4a29bfff 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java @@ -10,7 +10,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) +@CommandPermissions(level = Rank.TELNET_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Close server to non-admins.", usage = "/ [on | off]") public class Command_adminmode extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cuck.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cuck.java index b1011c8f..6ed44560 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cuck.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cuck.java @@ -11,9 +11,9 @@ import org.bukkit.ChatColor; @CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Cuck someone", usage = "/ ") -public class Command_cuck extends FreedomCommand +public class Command_cuck extends FreedomCommand { - + /* This command will not work on Paper because there was a patch to remove it. This will work on Spigot and Bukkit. */ @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -55,4 +55,4 @@ public class Command_cuck extends FreedomCommand } return Collections.emptyList(); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java index e44cc1a9..d3cbd1ed 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Make some noise.", usage = "/") public class Command_deafen extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java index 61b84743..258da68e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java @@ -141,11 +141,11 @@ public class Command_gtfo extends FreedomCommand .append(" - ") .append("Banning: ") .append(username); - playerMsg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + StringUtils.join(ips, ", ")); if (reason != null) { bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason); } + playerMsg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + StringUtils.join(ips, ", ")); FUtil.bcastMsg(bcast.toString()); // Kick player diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java new file mode 100644 index 00000000..9b12edd3 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java @@ -0,0 +1,203 @@ +package me.totalfreedom.totalfreedommod.command; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.world.WorldTime; +import me.totalfreedom.totalfreedommod.world.WorldWeather; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) +@CommandParameters(description = "Go to the MasterBuilderWorld.", + usage = "/ [time | weather ]", + aliases = "hw,hworld") +public class Command_hubworld extends FreedomCommand +{ + + private enum CommandMode + { + TELEPORT, TIME, WEATHER + } + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + CommandMode commandMode = null; + + if (args.length == 0) + { + commandMode = CommandMode.TELEPORT; + } + else if (args.length >= 2) + { + if ("time".equalsIgnoreCase(args[0])) + { + commandMode = CommandMode.TIME; + } + else if ("weather".equalsIgnoreCase(args[0])) + { + commandMode = CommandMode.WEATHER; + } + } + + if (commandMode == null) + { + return false; + } + + try + { + switch (commandMode) + { + case TELEPORT: + { + if (!(sender instanceof Player) || playerSender == null) + { + return true; + } + + World masterBuilderWorld = null; + try + { + masterBuilderWorld = plugin.wm.hubworld.getWorld(); + } + catch (Exception ex) + { + } + + if (masterBuilderWorld == null || playerSender.getWorld() == masterBuilderWorld) + { + msg("Going to the main world."); + playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); + } + else + { + msg("Going to the Hub"); + plugin.wm.hubworld.sendToWorld(playerSender); + } + + break; + } + case TIME: + { + assertCommandPerms(sender, playerSender); + + if (args.length == 2) + { + WorldTime timeOfDay = WorldTime.getByAlias(args[1]); + if (timeOfDay != null) + { + plugin.wm.hubworld.setTimeOfDay(timeOfDay); + msg("Hub time set to: " + timeOfDay.name()); + } + else + { + msg("Invalid time of day. Can be: sunrise, noon, sunset, midnight"); + } + } + else + { + return false; + } + + break; + } + case WEATHER: + { + assertCommandPerms(sender, playerSender); + + if (args.length == 2) + { + WorldWeather weatherMode = WorldWeather.getByAlias(args[1]); + if (weatherMode != null) + { + plugin.wm.hubworld.setWeatherMode(weatherMode); + msg("Hub weather set to: " + weatherMode.name()); + } + else + { + msg("Invalid weather mode. Can be: off, rain, storm"); + } + } + else + { + return false; + } + + break; + } + default: + { + return false; + } + } + } + catch (PermissionDeniedException ex) + { + if (ex.getMessage().isEmpty()) + { + return noPerms(); + } + sender.sendMessage(ex.getMessage()); + return true; + } + + return true; + } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return Collections.emptyList(); + } + if (args.length == 1) + { + return Arrays.asList("time", "weather"); + } + else if (args.length == 2) + { + if (args[0].equals("time")) + { + return Arrays.asList("morning", "noon", "evening", "night"); + } + else if (args[0].equals("weather")) + { + return Arrays.asList("off", "rain", "storm"); + } + } + return Collections.emptyList(); + } + + // TODO: Redo this properly + private void assertCommandPerms(CommandSender sender, Player playerSender) throws PermissionDeniedException + { + if (!(sender instanceof Player) || playerSender == null || !plugin.al.isSeniorAdmin(playerSender)) + { + throw new PermissionDeniedException(); + } + } + + private class PermissionDeniedException extends Exception + { + + private static final long serialVersionUID = 1L; + + private PermissionDeniedException() + { + super(""); + } + + private PermissionDeniedException(String string) + { + super(string); + } + } + +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java index eec6b01f..fafaeec9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Kick all non-admins on server.", usage = "/") public class Command_kicknoob extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java index 86957065..5d0daf93 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java @@ -19,24 +19,6 @@ public class Command_opall extends FreedomCommand boolean doSetGamemode = false; GameMode targetGamemode = GameMode.CREATIVE; - if (args.length != 0) - { - if (args[0].equals("-c")) - { - doSetGamemode = true; - targetGamemode = GameMode.CREATIVE; - } - else if (args[0].equals("-s")) - { - doSetGamemode = true; - targetGamemode = GameMode.SURVIVAL; - } - else if (args[0].equals("-a")) - { - doSetGamemode = true; - targetGamemode = GameMode.ADVENTURE; - } - } for (Player player : server.getOnlinePlayers()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java index eed8f149..412976d3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java @@ -6,7 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) +@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Manage permanently banned players and IPs.", usage = "/ reload") public class Command_permban extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java deleted file mode 100644 index 30dba22b..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java +++ /dev/null @@ -1,113 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import me.totalfreedom.totalfreedommod.rank.Rank; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = Rank.NON_OP, source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Shows nearby people sorted by distance.", usage = "/ [range]") -public class Command_radar extends FreedomCommand -{ - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - Location playerSenderos = playerSender.getLocation(); - - List radar_data = new ArrayList<>(); - - for (Player player : playerSenderos.getWorld().getPlayers()) - { - if (!player.equals(playerSender)) - { - try - { - radar_data.add(new RadarData(player, playerSenderos.distance(player.getLocation()), player.getLocation())); - } - catch (IllegalArgumentException ex) - { - } - } - } - - if (radar_data.isEmpty()) - { - msg("You are the only player in this world. (" + ChatColor.GREEN + "Forever alone..." + ChatColor.YELLOW + ")", ChatColor.YELLOW); //lol - return true; - } - - Collections.sort(radar_data, new RadarData()); - - msg("People nearby in " + playerSenderos.getWorld().getName() + ":", ChatColor.YELLOW); - - int countmax = 5; - if (args.length == 1) - { - try - { - countmax = Math.max(1, Math.min(64, Integer.parseInt(args[0]))); - } - catch (NumberFormatException nfex) - { - } - } - - for (RadarData i : radar_data) - { - msg(String.format("%s - %d", - i.player.getName(), - Math.round(i.distance)), ChatColor.YELLOW); - - if (--countmax <= 0) - { - break; - } - } - - return true; - } - - private class RadarData implements Comparator - { - - public Player player; - public double distance; - public Location location; - - public RadarData(Player player, double distance, Location location) - { - this.player = player; - this.distance = distance; - this.location = location; - } - - public RadarData() - { - } - - @Override - public int compare(RadarData t1, RadarData t2) - { - if (t1.distance > t2.distance) - { - return 1; - } - else if (t1.distance < t2.distance) - { - return -1; - } - else - { - return 0; - } - } - } - -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java index 2c4a60d0..0610c030 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) +@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Broadcasts the given message. Supports colors.", usage = "/ ") public class Command_rawsay extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java index 76eca6bb..e17f46c5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java @@ -42,8 +42,7 @@ public class Command_saconfig extends FreedomCommand case "clean": { - checkConsole(); - checkRank(Rank.TELNET_ADMIN); + checkRank(Rank.SENIOR_ADMIN); FUtil.adminAction(sender.getName(), "Cleaning admin list", true); plugin.al.deactivateOldEntries(true); @@ -54,7 +53,7 @@ public class Command_saconfig extends FreedomCommand case "reload": { - checkRank(Rank.SUPER_ADMIN); + checkRank(Rank.SENIOR_ADMIN); FUtil.adminAction(sender.getName(), "Reloading the admin list", true); plugin.al.load(); @@ -64,9 +63,7 @@ public class Command_saconfig extends FreedomCommand case "setrank": { - checkConsole(); - checkNotHostConsole(); - checkRank(Rank.SENIOR_CONSOLE); + checkRank(Rank.SENIOR_ADMIN); if (args.length < 3) { @@ -158,7 +155,6 @@ public class Command_saconfig extends FreedomCommand return false; } - checkConsole(); checkRank(Rank.TELNET_ADMIN); // Player already an admin? @@ -330,7 +326,6 @@ public class Command_saconfig extends FreedomCommand return false; } - checkConsole(); checkRank(Rank.TELNET_ADMIN); Player player = getPlayer(args[1]); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java index 82b1fa5e..d357f791 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java @@ -10,6 +10,8 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.ChatColor; +import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Unbans a player", usage = "/ [-r[estore]]") @@ -35,7 +37,8 @@ public class Command_unban extends FreedomCommand username = entry.getUsername(); ips.addAll(entry.getIps()); - FUtil.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); + FUtil.adminAction(sender.getName(), "Unbanning " + username, true); + playerMsg(sender, ChatColor.GRAY + username + " has been unbanned and IP is: " + StringUtils.join(ips, ", ")); plugin.bm.removeBan(plugin.bm.getByUsername(username)); if (args.length >= 2) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java new file mode 100644 index 00000000..4103e8dc --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java @@ -0,0 +1,34 @@ +package me.totalfreedom.totalfreedommod.command; + +import java.util.List; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) +@CommandParameters(description = "Information on how to vote", usage = "/", aliases = "ai") +public class Command_vote extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + List voteInfo = ConfigEntry.VOTING_INFO.getStringList(); + + if (voteInfo.isEmpty()) + { + msg("There is no voting information set in the config.", ChatColor.RED); + } + else + { + msg(FUtil.colorize(StringUtils.join(voteInfo, "\n"))); + } + + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index df57a373..9405e8f2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -111,6 +111,7 @@ public enum ConfigEntry NOADMIN_IPS(List.class, "noadmin_ips"), ADMIN_ONLY_MODE(Boolean.class, "admin_only_mode"), ADMIN_INFO(List.class, "admininfo"), + VOTING_INFO(List.class, "votinginfo"), MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"), AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"), // diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index 56c138cf..83cafef7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -141,6 +141,11 @@ public class ItemFun extends FreedomService { break; } + + if (player.getWorld().equals(plugin.wm.hubworld.getWorld()) && plugin.hwr.doRestrict(player)) + { + break; + } Location location = player.getLocation().clone(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/hub/HubWorldRestrictions.java b/src/main/java/me/totalfreedom/totalfreedommod/hub/HubWorldRestrictions.java new file mode 100644 index 00000000..1ae1341c --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/hub/HubWorldRestrictions.java @@ -0,0 +1,132 @@ +package me.totalfreedom.totalfreedommod.hub; + +import java.util.Arrays; +import java.util.List; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class HubWorldRestrictions extends FreedomService +{ + + public final List ALLOWED_COMMANDS = Arrays.asList( + "list", "opall", "gmc", "gms", "gma", "gmsp", "purgeall", "stfu", "tempban", "gtfo", "noob", "adminworld", "masterbuilderworld", "world", "nether", "spawn", "tpo", "tp", "expel", "item", "i", "give", "adminchat", "adventure", "creative", "survival", "spectator", "say", "blockcmd", "blockpvp", "blockredstone", "stoplag", "halt-activity", "nickclean", "nick", "nicknyan", "vanish", "verify", "verifynoadmin", "co", "coreprotect", "core", "mobpurge", "logs", "links", "vote"); + + public HubWorldRestrictions(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + + public boolean doRestrict(Player player) + { + if (!FUtil.isExecutive(player.getName()) && player.getWorld().equals(plugin.wm.hubworld.getWorld())) + { + return true; + } + + return false; + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onBlockPlace(BlockPlaceEvent event) + { + final Player player = event.getPlayer(); + + if (doRestrict(player)) + { + player.sendMessage(ChatColor.RED + "Only Executives can build in the Hub."); + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) + { + final Player player = event.getPlayer(); + + if (doRestrict(player)) + { + player.sendMessage(ChatColor.RED + "Only Executives can build in the Hub."); + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onPlayerInteract(PlayerInteractEvent event) + { + final Player player = event.getPlayer(); + + if (doRestrict(player)) + { + player.sendMessage(ChatColor.RED + "Only Executives can PVP in the Hub."); + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onArmorStandManipulate(PlayerArmorStandManipulateEvent event) + { + final Player player = event.getPlayer(); + + if (doRestrict(player)) + { + player.sendMessage(ChatColor.RED + "Only Executives can interact with armorstands in the Hub."); + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) + { + if (event.getDamager() instanceof Player) + { + Player player = (Player)event.getDamager(); + + if (doRestrict(player)) + { + player.sendMessage(ChatColor.RED + "Only Executives can damage entities in the Hub."); + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onCommandPreprocess(PlayerCommandPreprocessEvent event) + { + final Player player = event.getPlayer(); + if (doRestrict(player)) + { + String command = event.getMessage().split("\\s+")[0].substring(1, event.getMessage().split("\\s+")[0].length()).toLowerCase(); + + if (ALLOWED_COMMANDS.contains(command)) + { + event.setCancelled(false); + } + else if (command.startsWith("")) + { + player.sendMessage(ChatColor.RED + "Only Executives are allowed to execute commands in the Hub World!"); + event.setCancelled(true); + } + } + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/HubWorld.java b/src/main/java/me/totalfreedom/totalfreedommod/world/HubWorld.java new file mode 100644 index 00000000..3578c384 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/HubWorld.java @@ -0,0 +1,99 @@ +package me.totalfreedom.totalfreedommod.world; + +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.WorldType; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; + +public final class HubWorld extends CustomWorld +{ + + private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString(); + // + private WorldWeather weather = WorldWeather.OFF; + private WorldTime time = WorldTime.INHERIT; + + public HubWorld() + { + super("hubworld"); + } + + @Override + public void sendToWorld(Player player) + { + super.sendToWorld(player); + } + + @Override + protected World generateWorld() + { + final WorldCreator worldCreator = new WorldCreator(getName()); + worldCreator.generateStructures(false); + worldCreator.type(WorldType.NORMAL); + worldCreator.environment(World.Environment.NORMAL); + worldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS)); + + final World world = server.createWorld(worldCreator); + + world.setSpawnFlags(false, false); + world.setSpawnLocation(0, 50, 0); + + final Block welcomeSignBlock = world.getBlockAt(0, 50, 0); + welcomeSignBlock.setType(Material.OAK_SIGN); + org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState(); + + org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData(); + signData.setFacingDirection(BlockFace.NORTH); + + welcomeSign.setLine(0, ChatColor.GREEN + "Hub World"); + welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---"); + welcomeSign.setLine(2, ChatColor.YELLOW + "Spawn Point"); + welcomeSign.setLine(3, ChatColor.DARK_GRAY + "---"); + welcomeSign.update(); + + plugin.gr.commitGameRules(); + return world; + } + + public WorldWeather getWeatherMode() + { + return weather; + } + + public void setWeatherMode(final WorldWeather weatherMode) + { + this.weather = weatherMode; + + try + { + weatherMode.setWorldToWeather(getWorld()); + } + catch (Exception ex) + { + } + } + + public WorldTime getTimeOfDay() + { + return time; + } + + public void setTimeOfDay(final WorldTime timeOfDay) + { + this.time = timeOfDay; + + try + { + timeOfDay.setWorldToTime(getWorld()); + } + catch (Exception ex) + { + } + } + +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java index 14e503a7..91a9b257 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java @@ -23,6 +23,7 @@ public class WorldManager extends FreedomService public Flatlands flatlands; public AdminWorld adminworld; public MasterBuilderWorld masterBuilderWorld; + public HubWorld hubworld; public WorldManager(TotalFreedomMod plugin) { @@ -31,6 +32,7 @@ public class WorldManager extends FreedomService this.flatlands = new Flatlands(); this.adminworld = new AdminWorld(); this.masterBuilderWorld = new MasterBuilderWorld(); + this.hubworld = new HubWorld(); } @Override @@ -39,6 +41,7 @@ public class WorldManager extends FreedomService flatlands.getWorld(); adminworld.getWorld(); masterBuilderWorld.getWorld(); + hubworld.getWorld(); // Disable weather if (ConfigEntry.DISABLE_WEATHER.getBoolean()) @@ -59,6 +62,7 @@ public class WorldManager extends FreedomService flatlands.getWorld().save(); adminworld.getWorld().save(); masterBuilderWorld.getWorld().save(); + hubworld.getWorld().save(); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -109,6 +113,10 @@ public class WorldManager extends FreedomService { return; } + else if (event.getWorld().equals(hubworld.getWorld()) && hubworld.getWeatherMode() != WorldWeather.OFF) + { + return; + } } catch (Exception ex) { @@ -133,6 +141,10 @@ public class WorldManager extends FreedomService { return; } + else if (event.getWorld().equals(hubworld.getWorld()) && hubworld.getWeatherMode() != WorldWeather.OFF) + { + return; + } } catch (Exception ex) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f3088641..3d4bab56 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -315,6 +315,13 @@ admininfo: - ' &6- Report those breaking the rules' - ' &2- And apply on our forums at the link:' - ' &9www.totalfreedom.boards.net' + +# What to display in the vote command. +votinginfo: + - '&bVoting Links:' + - ' &6- https://minecraft-mp.com/server/228386/vote/' + - ' &2- https://minecraft-server-list.com/server/443272/vote/' + - ' &6- https://topg.org/Minecraft/in-518809' # What to display in the Master Builder info command. masterbuilderinfo: