mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
freezing, yml messages, and a funny lil command
This commit is contained in:
parent
2aba16cff2
commit
668488dfd1
@ -7,7 +7,6 @@ import me.totalfreedom.plex.cache.SQLPlayerData;
|
|||||||
import me.totalfreedom.plex.config.Config;
|
import me.totalfreedom.plex.config.Config;
|
||||||
import me.totalfreedom.plex.handlers.CommandHandler;
|
import me.totalfreedom.plex.handlers.CommandHandler;
|
||||||
import me.totalfreedom.plex.handlers.ListenerHandler;
|
import me.totalfreedom.plex.handlers.ListenerHandler;
|
||||||
import me.totalfreedom.plex.message.MessageManager;
|
|
||||||
import me.totalfreedom.plex.rank.RankManager;
|
import me.totalfreedom.plex.rank.RankManager;
|
||||||
import me.totalfreedom.plex.storage.MongoConnection;
|
import me.totalfreedom.plex.storage.MongoConnection;
|
||||||
import me.totalfreedom.plex.storage.RedisConnection;
|
import me.totalfreedom.plex.storage.RedisConnection;
|
||||||
@ -24,6 +23,7 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
private static Plex plugin;
|
private static Plex plugin;
|
||||||
public Config config;
|
public Config config;
|
||||||
|
public Config messages;
|
||||||
private StorageType storageType = StorageType.SQLITE;
|
private StorageType storageType = StorageType.SQLITE;
|
||||||
|
|
||||||
private SQLConnection sqlConnection;
|
private SQLConnection sqlConnection;
|
||||||
@ -34,7 +34,6 @@ public class Plex extends JavaPlugin
|
|||||||
private SQLPlayerData sqlPlayerData;
|
private SQLPlayerData sqlPlayerData;
|
||||||
|
|
||||||
private RankManager rankManager;
|
private RankManager rankManager;
|
||||||
private MessageManager messageManager;
|
|
||||||
|
|
||||||
public static Plex get()
|
public static Plex get()
|
||||||
{
|
{
|
||||||
@ -46,6 +45,7 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
plugin = this;
|
plugin = this;
|
||||||
config = new Config(this, "config.yml");
|
config = new Config(this, "config.yml");
|
||||||
|
messages = new Config(this, "messages.yml");
|
||||||
saveResource("database.db", false);
|
saveResource("database.db", false);
|
||||||
|
|
||||||
sqlConnection = new SQLConnection();
|
sqlConnection = new SQLConnection();
|
||||||
@ -64,6 +64,7 @@ public class Plex extends JavaPlugin
|
|||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
config.load();
|
config.load();
|
||||||
|
messages.load();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -93,10 +94,6 @@ public class Plex extends JavaPlugin
|
|||||||
rankManager.importDefaultRanks();
|
rankManager.importDefaultRanks();
|
||||||
PlexLog.log("Rank Manager initialized");
|
PlexLog.log("Rank Manager initialized");
|
||||||
|
|
||||||
messageManager = new MessageManager();
|
|
||||||
messageManager.generateMessages();
|
|
||||||
PlexLog.log("Message Manager initialized");
|
|
||||||
|
|
||||||
generateWorlds();
|
generateWorlds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,5 +20,14 @@ public class PlayerCache
|
|||||||
{
|
{
|
||||||
return plexPlayerMap;
|
return plexPlayerMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PunishedPlayer getPunishedPlayer(UUID uuid)
|
||||||
|
{
|
||||||
|
return getPunishedPlayerMap().get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlexPlayer getPlexPlayer(UUID uuid)
|
||||||
|
{
|
||||||
|
return getPlexPlayerMap().get(uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
if (!plexPlayer.getRankFromString().isAtleast(getLevel()))
|
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
//TODO: Enter <insert level> only and higher msg
|
//TODO: Enter <insert level> only and higher msg
|
||||||
return true;
|
return true;
|
||||||
@ -91,7 +91,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
} else {
|
} else {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
if (!plexPlayer.getRankFromString().isAtleast(getLevel()))
|
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
//TODO: Enter <insert level> only and higher msg
|
//TODO: Enter <insert level> only and higher msg
|
||||||
return true;
|
return true;
|
||||||
@ -111,7 +111,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
{
|
{
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
if (plexPlayer.getRankFromString().isAtleast(getLevel()))
|
if (plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
return onTabComplete(sender, args);
|
return onTabComplete(sender, args);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,5 +10,5 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
public @interface CommandPermissions
|
public @interface CommandPermissions
|
||||||
{
|
{
|
||||||
Rank level() default Rank.IMPOSTOR;
|
Rank level() default Rank.IMPOSTOR;
|
||||||
RequiredCommandSource source();
|
RequiredCommandSource source() default RequiredCommandSource.ANY;
|
||||||
}
|
}
|
133
src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java
Normal file
133
src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package me.totalfreedom.plex.command.impl;
|
||||||
|
|
||||||
|
import me.totalfreedom.plex.cache.PlayerCache;
|
||||||
|
import me.totalfreedom.plex.command.PlexCommand;
|
||||||
|
import me.totalfreedom.plex.command.annotations.CommandParameters;
|
||||||
|
import me.totalfreedom.plex.command.annotations.CommandPermissions;
|
||||||
|
import me.totalfreedom.plex.command.source.RequiredCommandSource;
|
||||||
|
import me.totalfreedom.plex.util.PlexUtils;
|
||||||
|
import me.totalfreedom.plex.world.BlockMapChunkGenerator;
|
||||||
|
import me.totalfreedom.plex.world.CustomWorld;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.*;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@CommandParameters(description = "Subliminal message.")
|
||||||
|
@CommandPermissions(source = RequiredCommandSource.IN_GAME)
|
||||||
|
public class FionnCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
public static boolean ENABLED = false;
|
||||||
|
public static Map<Player, Location> LOCATION_CACHE = new HashMap<>();
|
||||||
|
|
||||||
|
public FionnCMD()
|
||||||
|
{
|
||||||
|
super("fionn");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if (!player.getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f")))
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.RED + "You cannot run this command!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String name = "fionn";
|
||||||
|
LinkedHashMap<Material, Integer> map = new LinkedHashMap<>();
|
||||||
|
map.put(Material.CRIMSON_NYLIUM, 1);
|
||||||
|
map.put(Material.BEDROCK, 1);
|
||||||
|
World fionnWorld = new CustomWorld(name, new BlockMapChunkGenerator(map)).generate();
|
||||||
|
ENABLED = true;
|
||||||
|
fionnWorld.setTime(0);
|
||||||
|
fionnWorld.getBlockAt(0, 5, 0).setType(Material.BARRIER);
|
||||||
|
Strider fionn = (Strider) fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 6, -180, -3), EntityType.STRIDER);
|
||||||
|
fionn.setCustomNameVisible(true);
|
||||||
|
fionn.setCustomName(ChatColor.GREEN + "fionn");
|
||||||
|
fionn.setAI(false);
|
||||||
|
Enderman elmon = (Enderman) fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 0, 0, 18), EntityType.ENDERMAN);
|
||||||
|
elmon.setCustomNameVisible(true);
|
||||||
|
elmon.setCustomName(ChatColor.RED + "elmon");
|
||||||
|
elmon.setInvulnerable(true);
|
||||||
|
elmon.setAware(false);
|
||||||
|
elmon.setGravity(true);
|
||||||
|
// platforms in cage
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 10, 5, -2), new Location(fionnWorld, 14, 5, 2), Material.SMOOTH_STONE);
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 10, 9, -2), new Location(fionnWorld, 14, 9, 2), Material.SMOOTH_STONE_SLAB);
|
||||||
|
// iron bars of cage
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS);
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS);
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS);
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS);
|
||||||
|
// lava
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 10, 1, -2), new Location(fionnWorld, 14, 0, 2), Material.LAVA);
|
||||||
|
|
||||||
|
// iron bars of platform
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 12, 2, 6), new Location(fionnWorld, 12, 5, 6), Material.IRON_BARS);
|
||||||
|
// platform
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 11, 6, 7), new Location(fionnWorld, 13, 6, 5), Material.SMOOTH_STONE_SLAB);
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
p.setInvisible(true);
|
||||||
|
LOCATION_CACHE.put(p, p.getLocation());
|
||||||
|
p.teleport(new Location(fionnWorld, 0, 5, 0, -90, 0));
|
||||||
|
PlayerCache.getPlexPlayer(p.getUniqueId()).setFrozen(true);
|
||||||
|
}
|
||||||
|
lateFakeChat("elmon", "fionn! i'm sorry for not being your sex slave...", ChatColor.RED, 20);
|
||||||
|
lateFakeChat("fionn", "it's too late for that now...", ChatColor.GREEN, 60);
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
PlexUtils.setBlocks(new Location(fionnWorld, 13, 5, -1), new Location(fionnWorld, 11, 5, 1), Material.AIR);
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 100);
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
fionn.teleport(new Location(fionnWorld, 2.5, 5.5, 0, 90, -10));
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 160);
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
fionn.remove();
|
||||||
|
elmon.remove();
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
p.setInvisible(false);
|
||||||
|
Location location = LOCATION_CACHE.get(p);
|
||||||
|
if (location != null)
|
||||||
|
p.teleport(location);
|
||||||
|
PlayerCache.getPlexPlayer(p.getUniqueId()).setFrozen(false);
|
||||||
|
}
|
||||||
|
LOCATION_CACHE.clear();
|
||||||
|
ENABLED = false;
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void lateFakeChat(String name, String message, ChatColor color, int delay)
|
||||||
|
{
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Bukkit.broadcastMessage(color + name + ChatColor.GRAY + ": " + ChatColor.WHITE + message);
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, delay);
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,10 @@ import org.bukkit.command.CommandSender;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static me.totalfreedom.plex.util.PlexUtils.tl;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(usage = "/<command>", aliases = "tst,tast", description = "HELLO")
|
@CommandParameters(aliases = "tst,tast", description = "HELLO")
|
||||||
public class TestCMD extends PlexCommand
|
public class TestCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
public TestCMD() {
|
public TestCMD() {
|
||||||
@ -20,8 +22,9 @@ public class TestCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args)
|
||||||
sender.sendMessage(plugin.getMessageManager().getMessage("test"));
|
{
|
||||||
|
sender.sendMessage(tl("variableTest", sender.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package me.totalfreedom.plex.command.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import me.totalfreedom.plex.Plex;
|
||||||
|
import me.totalfreedom.plex.command.PlexCommand;
|
||||||
|
import me.totalfreedom.plex.command.annotations.CommandParameters;
|
||||||
|
import me.totalfreedom.plex.command.annotations.CommandPermissions;
|
||||||
|
import me.totalfreedom.plex.command.source.RequiredCommandSource;
|
||||||
|
import me.totalfreedom.plex.rank.enums.Rank;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static me.totalfreedom.plex.util.PlexUtils.tl;
|
||||||
|
|
||||||
|
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME)
|
||||||
|
@CommandParameters(description = "Teleport to a world.", usage = "/<command> <world>")
|
||||||
|
public class WorldCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
public WorldCMD() {
|
||||||
|
super("world");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
Player player = (Player) sender;
|
||||||
|
World world = Bukkit.getWorld(args[0]);
|
||||||
|
player.teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
|
||||||
|
sender.sendMessage(tl("playerWorldTeleport", world.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
List<String> worlds = new ArrayList<>();
|
||||||
|
for (World world : Bukkit.getWorlds())
|
||||||
|
worlds.add(world.getName());
|
||||||
|
if (args.length == 1)
|
||||||
|
return worlds;
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,8 +2,10 @@ package me.totalfreedom.plex.handlers;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import me.totalfreedom.plex.command.PlexCommand;
|
import me.totalfreedom.plex.command.PlexCommand;
|
||||||
|
import me.totalfreedom.plex.command.impl.FionnCMD;
|
||||||
import me.totalfreedom.plex.command.impl.PlexCMD;
|
import me.totalfreedom.plex.command.impl.PlexCMD;
|
||||||
import me.totalfreedom.plex.command.impl.TestCMD;
|
import me.totalfreedom.plex.command.impl.TestCMD;
|
||||||
|
import me.totalfreedom.plex.command.impl.WorldCMD;
|
||||||
import me.totalfreedom.plex.util.PlexLog;
|
import me.totalfreedom.plex.util.PlexLog;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,6 +19,8 @@ public class CommandHandler
|
|||||||
{
|
{
|
||||||
commands.add(new TestCMD());
|
commands.add(new TestCMD());
|
||||||
commands.add(new PlexCMD());
|
commands.add(new PlexCMD());
|
||||||
|
commands.add(new FionnCMD());
|
||||||
|
commands.add(new WorldCMD());
|
||||||
|
|
||||||
PlexLog.log(String.format("Registered %s commands!", commands.size()));
|
PlexLog.log(String.format("Registered %s commands!", commands.size()));
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package me.totalfreedom.plex.handlers;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import me.totalfreedom.plex.listener.PlexListener;
|
import me.totalfreedom.plex.listener.PlexListener;
|
||||||
import me.totalfreedom.plex.listener.impl.ChatListener;
|
import me.totalfreedom.plex.listener.impl.ChatListener;
|
||||||
|
import me.totalfreedom.plex.listener.impl.FreezeListener;
|
||||||
import me.totalfreedom.plex.listener.impl.PlayerListener;
|
import me.totalfreedom.plex.listener.impl.PlayerListener;
|
||||||
import me.totalfreedom.plex.listener.impl.WorldListener;
|
import me.totalfreedom.plex.listener.impl.WorldListener;
|
||||||
import me.totalfreedom.plex.util.PlexLog;
|
import me.totalfreedom.plex.util.PlexLog;
|
||||||
@ -19,6 +20,7 @@ public class ListenerHandler
|
|||||||
listeners.add(new ChatListener());
|
listeners.add(new ChatListener());
|
||||||
listeners.add(new PlayerListener());
|
listeners.add(new PlayerListener());
|
||||||
listeners.add(new WorldListener());
|
listeners.add(new WorldListener());
|
||||||
|
listeners.add(new FreezeListener());
|
||||||
|
|
||||||
PlexLog.log(String.format("Registered %s listeners!", listeners.size()));
|
PlexLog.log(String.format("Registered %s listeners!", listeners.size()));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package me.totalfreedom.plex.listener.impl;
|
||||||
|
|
||||||
|
import me.totalfreedom.plex.cache.PlayerCache;
|
||||||
|
import me.totalfreedom.plex.listener.PlexListener;
|
||||||
|
import me.totalfreedom.plex.player.PlexPlayer;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
|
public class FreezeListener extends PlexListener
|
||||||
|
{
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMove(PlayerMoveEvent e)
|
||||||
|
{
|
||||||
|
PlexPlayer player = PlayerCache.getPlexPlayer(e.getPlayer().getUniqueId());
|
||||||
|
if (player.isFrozen())
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
@ -5,11 +5,13 @@ import me.totalfreedom.plex.Plex;
|
|||||||
import me.totalfreedom.plex.cache.MongoPlayerData;
|
import me.totalfreedom.plex.cache.MongoPlayerData;
|
||||||
import me.totalfreedom.plex.cache.PlayerCache;
|
import me.totalfreedom.plex.cache.PlayerCache;
|
||||||
import me.totalfreedom.plex.cache.SQLPlayerData;
|
import me.totalfreedom.plex.cache.SQLPlayerData;
|
||||||
|
import me.totalfreedom.plex.command.impl.FionnCMD;
|
||||||
import me.totalfreedom.plex.listener.PlexListener;
|
import me.totalfreedom.plex.listener.PlexListener;
|
||||||
import me.totalfreedom.plex.player.PlexPlayer;
|
import me.totalfreedom.plex.player.PlexPlayer;
|
||||||
import me.totalfreedom.plex.player.PunishedPlayer;
|
import me.totalfreedom.plex.player.PunishedPlayer;
|
||||||
import me.totalfreedom.plex.util.PlexLog;
|
import me.totalfreedom.plex.util.PlexLog;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -22,6 +24,7 @@ public class PlayerListener extends PlexListener
|
|||||||
private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null;
|
private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null;
|
||||||
private final SQLPlayerData sqlPlayerData = plugin.getSqlPlayerData() != null ? plugin.getSqlPlayerData() : null;
|
private final SQLPlayerData sqlPlayerData = plugin.getSqlPlayerData() != null ? plugin.getSqlPlayerData() : null;
|
||||||
|
|
||||||
|
// setting up a player's data
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerSetup(PlayerJoinEvent event)
|
public void onPlayerSetup(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
@ -80,6 +83,7 @@ public class PlayerListener extends PlexListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// saving the player's data
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerSave(PlayerQuitEvent event)
|
public void onPlayerSave(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
@ -98,4 +102,20 @@ public class PlayerListener extends PlexListener
|
|||||||
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
|
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unrelated player quitting
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent e)
|
||||||
|
{
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(player.getUniqueId());
|
||||||
|
|
||||||
|
if (FionnCMD.ENABLED)
|
||||||
|
{
|
||||||
|
player.setInvisible(false);
|
||||||
|
plexPlayer.setFrozen(false);
|
||||||
|
Location location = FionnCMD.LOCATION_CACHE.get(player);
|
||||||
|
if (location != null)
|
||||||
|
player.teleport(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,14 @@ import me.totalfreedom.plex.cache.PlayerCache;
|
|||||||
import me.totalfreedom.plex.listener.PlexListener;
|
import me.totalfreedom.plex.listener.PlexListener;
|
||||||
import me.totalfreedom.plex.player.PlexPlayer;
|
import me.totalfreedom.plex.player.PlexPlayer;
|
||||||
import me.totalfreedom.plex.rank.enums.Rank;
|
import me.totalfreedom.plex.rank.enums.Rank;
|
||||||
import me.totalfreedom.plex.util.PlexUtils;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
|
|
||||||
|
import static me.totalfreedom.plex.util.PlexUtils.tl;
|
||||||
|
|
||||||
public class WorldListener extends PlexListener
|
public class WorldListener extends PlexListener
|
||||||
{
|
{
|
||||||
@ -22,12 +25,22 @@ public class WorldListener extends PlexListener
|
|||||||
{
|
{
|
||||||
case "adminworld":
|
case "adminworld":
|
||||||
{
|
{
|
||||||
if (plexPlayer.getRankFromString().isAtleast(Rank.ADMIN))
|
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||||
return;
|
return;
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
player.sendMessage(PlexUtils.color(plugin.getMessageManager().getMessage("noAdminWorldBlockPlace")));
|
player.sendMessage(tl("noAdminWorldBlockPlace"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntitySpawn(EntitySpawnEvent e)
|
||||||
|
{
|
||||||
|
if (!e.getLocation().getWorld().getName().equals("fionn"))
|
||||||
|
return;
|
||||||
|
if (e.getEntityType() != EntityType.SLIME)
|
||||||
|
return;
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,70 +0,0 @@
|
|||||||
package me.totalfreedom.plex.message;
|
|
||||||
|
|
||||||
import me.totalfreedom.plex.Plex;
|
|
||||||
import me.totalfreedom.plex.util.PlexLog;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.json.JSONTokener;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class MessageManager
|
|
||||||
{
|
|
||||||
private final File messages;
|
|
||||||
|
|
||||||
public MessageManager()
|
|
||||||
{
|
|
||||||
this.messages = new File(Plex.get().getDataFolder(), "messages.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generateMessages()
|
|
||||||
{
|
|
||||||
if (messages.exists())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
messages.createNewFile();
|
|
||||||
|
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
if (obj.length() == 0)
|
|
||||||
{
|
|
||||||
obj.put("test", "this is a test message!");
|
|
||||||
obj.put("noAdminWorldBlockPlace", "&cYou are not allowed to place blocks in the admin world!");
|
|
||||||
obj.put("noAdminWorldBlockBreak", "&cYou are not allowed to break blocks in the admin world!");
|
|
||||||
FileWriter writer = new FileWriter(messages);
|
|
||||||
writer.append(obj.toString(4));
|
|
||||||
writer.flush();
|
|
||||||
writer.close();
|
|
||||||
PlexLog.log("Generating messages.json");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage(String s)
|
|
||||||
{
|
|
||||||
if (!messages.exists())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileInputStream stream = new FileInputStream(messages);
|
|
||||||
JSONTokener tokener = new JSONTokener(stream);
|
|
||||||
JSONObject object = new JSONObject(tokener);
|
|
||||||
return (String) object.get(s);
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -39,6 +39,8 @@ public class PlexPlayer
|
|||||||
|
|
||||||
private List<String> ips;
|
private List<String> ips;
|
||||||
|
|
||||||
|
private boolean frozen;
|
||||||
|
|
||||||
public PlexPlayer() {}
|
public PlexPlayer() {}
|
||||||
|
|
||||||
public PlexPlayer(UUID playerUUID)
|
public PlexPlayer(UUID playerUUID)
|
||||||
@ -57,6 +59,8 @@ public class PlexPlayer
|
|||||||
this.ips = new ArrayList<>();
|
this.ips = new ArrayList<>();
|
||||||
|
|
||||||
this.rank = "";
|
this.rank = "";
|
||||||
|
|
||||||
|
this.frozen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rank getRankFromString()
|
public Rank getRankFromString()
|
||||||
|
@ -95,6 +95,6 @@ public class RankManager
|
|||||||
|
|
||||||
public boolean isAdmin(PlexPlayer plexPlayer)
|
public boolean isAdmin(PlexPlayer plexPlayer)
|
||||||
{
|
{
|
||||||
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtleast(Rank.ADMIN);
|
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public enum Rank
|
|||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAtleast(Rank rank)
|
public boolean isAtLeast(Rank rank)
|
||||||
{
|
{
|
||||||
return getLevel() >= rank.getLevel();
|
return getLevel() >= rank.getLevel();
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,13 @@ package me.totalfreedom.plex.util;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import me.totalfreedom.plex.Plex;
|
import me.totalfreedom.plex.Plex;
|
||||||
|
import me.totalfreedom.plex.config.Config;
|
||||||
import me.totalfreedom.plex.storage.StorageType;
|
import me.totalfreedom.plex.storage.StorageType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.PluginCommandYamlParser;
|
import org.bukkit.command.PluginCommandYamlParser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -68,8 +67,61 @@ public class PlexUtils
|
|||||||
return ChatColor.translateAlternateColorCodes('&', s);
|
return ChatColor.translateAlternateColorCodes('&', s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if you think the name of this method is dumb feel free to change it i just thought it'd be cool
|
||||||
|
public static String tl(String s, Object... objects)
|
||||||
|
{
|
||||||
|
Plex plugin = Plex.get();
|
||||||
|
if (s.equals("baseColor") || s.equals("errorColor"))
|
||||||
|
return getChatColorFromConfig(plugin.messages, (s.equals("baseColor") ? ChatColor.GRAY : ChatColor.RED), s).toString();
|
||||||
|
String f = plugin.messages.getString(s);
|
||||||
|
if (f == null)
|
||||||
|
return ChatColor.RED + "No message";
|
||||||
|
for (Object object : objects)
|
||||||
|
f = f.replace("<v>", String.valueOf(object));
|
||||||
|
ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor");
|
||||||
|
ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor");
|
||||||
|
f = f.replaceAll("<r>", base.toString());
|
||||||
|
f = f.replaceAll("<e>", error.toString());
|
||||||
|
return base + f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChatColor getChatColorFromConfig(Config config, ChatColor def, String path)
|
||||||
|
{
|
||||||
|
ChatColor color;
|
||||||
|
if (config.getString(path) == null)
|
||||||
|
color = def;
|
||||||
|
else if (ChatColor.getByChar(config.getString(path)) == null)
|
||||||
|
color = def;
|
||||||
|
else
|
||||||
|
color = ChatColor.getByChar(config.getString(path));
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
public static void warpToWorld(Player player, World world)
|
public static void warpToWorld(Player player, World world)
|
||||||
{
|
{
|
||||||
player.teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0), 0));
|
player.teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setBlocks(Location c1, Location c2, Material material)
|
||||||
|
{
|
||||||
|
if (!c1.getWorld().getName().equals(c1.getWorld().getName()))
|
||||||
|
return;
|
||||||
|
int sy = Math.min(c1.getBlockY(), c2.getBlockY()),
|
||||||
|
ey = Math.max(c1.getBlockY(), c2.getBlockY()),
|
||||||
|
sx = Math.min(c1.getBlockX(), c2.getBlockX()),
|
||||||
|
ex = Math.max(c1.getBlockX(), c2.getBlockX()),
|
||||||
|
sz = Math.min(c1.getBlockZ(), c2.getBlockZ()),
|
||||||
|
ez = Math.max(c1.getBlockZ(), c2.getBlockZ());
|
||||||
|
World world = c1.getWorld();
|
||||||
|
for (int y = sy; y <= ey; y++)
|
||||||
|
{
|
||||||
|
for (int x = sx; x <= ex; x++)
|
||||||
|
{
|
||||||
|
for (int z = sz; z <= ez; z++)
|
||||||
|
{
|
||||||
|
world.getBlockAt(x, y, z).setType(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package me.totalfreedom.plex.world;
|
||||||
|
|
||||||
|
import me.totalfreedom.plex.Plex;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class BlockMapChunkGenerator extends FlatChunkGenerator
|
||||||
|
{
|
||||||
|
private static Plex plugin = Plex.get();
|
||||||
|
|
||||||
|
protected LinkedHashMap<Material, Integer> blockMap;
|
||||||
|
|
||||||
|
public BlockMapChunkGenerator(LinkedHashMap<Material, Integer> blockMap, BlockPopulator... populators)
|
||||||
|
{
|
||||||
|
super(0, populators);
|
||||||
|
this.blockMap = blockMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createLoopChunkData(int x, int y, int z, ChunkData chunk)
|
||||||
|
{
|
||||||
|
int height = -1;
|
||||||
|
for (int i : blockMap.values())
|
||||||
|
height += i;
|
||||||
|
for (Map.Entry<Material, Integer> entry : blockMap.entrySet())
|
||||||
|
{
|
||||||
|
for (int i = 0; i < entry.getValue(); i++, height--)
|
||||||
|
chunk.setBlock(x, height, z, entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,37 +5,26 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ConfigurationChunkGenerator extends FlatChunkGenerator
|
public class ConfigurationChunkGenerator extends BlockMapChunkGenerator
|
||||||
{
|
{
|
||||||
private static Plex plugin = Plex.get();
|
private static Plex plugin = Plex.get();
|
||||||
|
|
||||||
private final String worldName;
|
|
||||||
|
|
||||||
public ConfigurationChunkGenerator(String worldName, BlockPopulator... populators)
|
public ConfigurationChunkGenerator(String worldName, BlockPopulator... populators)
|
||||||
{
|
{
|
||||||
super(0, populators);
|
super(createBlockMap(worldName), populators);
|
||||||
this.worldName = worldName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static LinkedHashMap<Material, Integer> createBlockMap(String worldName)
|
||||||
public void createLoopChunkData(int x, int y, int z, ChunkData chunk)
|
|
||||||
{
|
{
|
||||||
int height = -1;
|
LinkedHashMap<Material, Integer> blockMap = new LinkedHashMap<>();
|
||||||
Map<Material, Integer> blocks = new LinkedHashMap<>();
|
|
||||||
for (String key : plugin.config.getConfigurationSection("worlds." + worldName + ".parameters").getKeys(false))
|
for (String key : plugin.config.getConfigurationSection("worlds." + worldName + ".parameters").getKeys(false))
|
||||||
{
|
{
|
||||||
Material material = Material.getMaterial(key.toUpperCase());
|
Material material = Material.getMaterial(key.toUpperCase());
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
int count = plugin.config.getInt("worlds." + worldName + ".parameters." + key);
|
int count = plugin.config.getInt("worlds." + worldName + ".parameters." + key);
|
||||||
height += count;
|
blockMap.put(material, count);
|
||||||
blocks.put(material, count);
|
|
||||||
}
|
|
||||||
for (Map.Entry<Material, Integer> entry : blocks.entrySet())
|
|
||||||
{
|
|
||||||
for (int i = 0; i < entry.getValue(); i++, height--)
|
|
||||||
chunk.setBlock(x, height, z, entry.getKey());
|
|
||||||
}
|
}
|
||||||
|
return blockMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ public class CustomWorld extends WorldCreator
|
|||||||
|
|
||||||
private final CustomChunkGenerator chunks;
|
private final CustomChunkGenerator chunks;
|
||||||
|
|
||||||
private CustomWorld(String name, CustomChunkGenerator generator)
|
public CustomWorld(String name, CustomChunkGenerator generator)
|
||||||
{
|
{
|
||||||
super(name);
|
super(name);
|
||||||
this.chunks = generator;
|
this.chunks = generator;
|
||||||
|
22
src/main/resources/messages.yml
Normal file
22
src/main/resources/messages.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Plex Messages File
|
||||||
|
|
||||||
|
# Messages in here will be placed in for certain commands, actions, etc.
|
||||||
|
# Warning: not all commands have customizable messages
|
||||||
|
|
||||||
|
# Base color - the main color prefix; will be used following each of the messages below
|
||||||
|
# Error color - the color of an error; will be used when an error is thrown from a command
|
||||||
|
baseColor: "7"
|
||||||
|
errorColor: "c"
|
||||||
|
|
||||||
|
# Variables <v> - these are code-defined replacements for things that should be inserted into messages. (e.g. names, statuses, numbers)
|
||||||
|
# if any of these variables are defined within a message, some documentation is provided to give more context to what the variables indicate.
|
||||||
|
# message variables are used in numerical order that is unchangeable from this file.
|
||||||
|
|
||||||
|
# Reset color <r> - this will reset the color of the message to the base color defined above.
|
||||||
|
# Error color <e> - this will make the color of the message the error color defined above.
|
||||||
|
|
||||||
|
test: this is a test message!
|
||||||
|
variableTest: variable test with <v>!
|
||||||
|
noAdminWorldBlockPlace: <e>You are not allowed to place blocks in the admin world!
|
||||||
|
noAdminWorldBlockBreak: <e>You are not allowed to break blocks in the admin world!
|
||||||
|
playerWorldTeleport: You have been teleported to <v>.
|
Loading…
Reference in New Issue
Block a user