diff --git a/.gitignore b/.gitignore index 106e908..7b20272 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ dist -api -.idea \ No newline at end of file +api \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index 946ef55..04af7e2 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,4 +1,4 @@ -main: xenon.Main +main: xenon.main name: xenon version: 1.0 api-version: 1.16 diff --git a/src/xenon/Main.java b/src/xenon/Main.java deleted file mode 100644 index e050b40..0000000 --- a/src/xenon/Main.java +++ /dev/null @@ -1,103 +0,0 @@ -package xenon; - - - -import org.bukkit.Bukkit; -import org.bukkit.plugin.PluginManager; -import xenon.commands.DiscordCommandExecutor; -import xenon.commands.HelpCommandExecutor; -import xenon.commands.StatsCommandExecutor; -import xenon.commands.JoindateCommandExecutor; -import xenon.commands.KillCommandExecutor; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; -import xenon.events.AntiIllegals; -import xenon.events.AntiNetherRoof; -import xenon.events.AntiSpam; -import xenon.events.BoatflyPatch; -import xenon.events.CustomChat; -import xenon.events.CustomMessages; -import xenon.events.CustomTab; -import xenon.events.ElytraflyPatch; -import xenon.events.LimitArmorStands; -import xenon.events.RandomRespawn; -import xenon.misc.Config; - -/** - * - * @author hanna - */ - - public class Main extends JavaPlugin implements Listener { - - private Config config; - private static Main instance; - - @Override - public void onLoad() { - this.config = new Config(); - } - - @Override - public void onEnable() { - // Get an instance of the main class - instance = this; - - // Initialize default config values if not set - initConfig(); - - // Register commands and listeners - registerListener(); - commandRegistration(); - - LimitArmorStands.limit(); - CustomTab.tab(); - } - - @Override - public void onDisable() { - // Save Config to file - this.config.save(); - } - - private void registerListener() { - // Registering Bukkit Listeners - PluginManager pluginManager = Bukkit.getPluginManager(); - - pluginManager.registerEvents(new AntiIllegals(), this); - pluginManager.registerEvents(new AntiNetherRoof(), this); - pluginManager.registerEvents(new AntiSpam(), this); - pluginManager.registerEvents(new BoatflyPatch(), this); - pluginManager.registerEvents(new CustomChat(), this); - pluginManager.registerEvents(new CustomMessages(), this); - pluginManager.registerEvents(new ElytraflyPatch(), this); - pluginManager.registerEvents(new RandomRespawn(), this); - } - - private void commandRegistration() { - // Registering Bukkit commands - this.getCommand("kill").setExecutor(new KillCommandExecutor()); - this.getCommand("help").setExecutor(new HelpCommandExecutor()); - this.getCommand("discord").setExecutor(new DiscordCommandExecutor()); - this.getCommand("stats").setExecutor(new StatsCommandExecutor()); - this.getCommand("joindate").setExecutor(new JoindateCommandExecutor()); - } - - private void initConfig() { - // Set default values - if (this.config.getConfig().get("Discord") != null) { - return; - } - - this.config.getConfig().set("Discord", "https://discord.gg/gHn8aqTR5j"); - this.config.save(); - } - - public Config getConfiguration() { - return config; - } - - public static Main getInstance() { - return instance; - } -} \ No newline at end of file diff --git a/src/xenon/commands/Discord.java b/src/xenon/commands/Discord.java new file mode 100644 index 0000000..38ddcb5 --- /dev/null +++ b/src/xenon/commands/Discord.java @@ -0,0 +1,22 @@ +package xenon.commands; + + +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +/** + * + * @author hanna + */ +public class Discord implements Listener, CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) { + Player p = (Player) sender; + p.sendMessage("§bClick on the link to join: §dhttps://discord.gg/gHn8aqTR5j"); + return true; + } +} diff --git a/src/xenon/commands/DiscordCommandExecutor.java b/src/xenon/commands/DiscordCommandExecutor.java deleted file mode 100644 index af19445..0000000 --- a/src/xenon/commands/DiscordCommandExecutor.java +++ /dev/null @@ -1,34 +0,0 @@ -package xenon.commands; - - -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.Command; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import xenon.Main; - -/** - * - * @author hanna - */ -public class DiscordCommandExecutor implements Listener, CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) { - Player p = (Player) sender; - String discordLink; - - if (Main.getInstance().getConfiguration().getConfig().get("Discord") == null) { - discordLink = "https://discord.gg/gHn8aqTR5j"; - - Main.getInstance().getConfiguration().getConfig().set("Discord", "https://discord.gg/gHn8aqTR5j"); - Main.getInstance().getConfiguration().save(); - } else { - discordLink = Main.getInstance().getConfiguration().getConfig().getString("Discord"); - } - - p.sendMessage("§bClick on the link to join: §d" + discordLink); - return true; - } -} diff --git a/src/xenon/commands/HelpCommandExecutor.java b/src/xenon/commands/Help.java similarity index 91% rename from src/xenon/commands/HelpCommandExecutor.java rename to src/xenon/commands/Help.java index c662f27..05e15ca 100644 --- a/src/xenon/commands/HelpCommandExecutor.java +++ b/src/xenon/commands/Help.java @@ -10,7 +10,7 @@ import org.bukkit.event.Listener; * * @author hanna */ -public class HelpCommandExecutor implements Listener, CommandExecutor { +public class Help implements Listener, CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) { diff --git a/src/xenon/commands/JoindateCommandExecutor.java b/src/xenon/commands/Joindate.java similarity index 94% rename from src/xenon/commands/JoindateCommandExecutor.java rename to src/xenon/commands/Joindate.java index 3ef323d..70839a9 100644 --- a/src/xenon/commands/JoindateCommandExecutor.java +++ b/src/xenon/commands/Joindate.java @@ -15,7 +15,7 @@ import org.bukkit.event.Listener; * * @author hanna */ -public class JoindateCommandExecutor implements Listener, CommandExecutor { +public class Joindate implements Listener, CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) { diff --git a/src/xenon/commands/KillCommandExecutor.java b/src/xenon/commands/Kill.java similarity index 85% rename from src/xenon/commands/KillCommandExecutor.java rename to src/xenon/commands/Kill.java index c5fde0c..dc0db3a 100644 --- a/src/xenon/commands/KillCommandExecutor.java +++ b/src/xenon/commands/Kill.java @@ -10,7 +10,7 @@ import org.bukkit.event.Listener; * * @author hanna */ -public class KillCommandExecutor implements Listener, CommandExecutor { +public class Kill implements Listener, CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) { diff --git a/src/xenon/commands/StatsCommandExecutor.java b/src/xenon/commands/Stats.java similarity index 97% rename from src/xenon/commands/StatsCommandExecutor.java rename to src/xenon/commands/Stats.java index b2d1cb8..52f3395 100644 --- a/src/xenon/commands/StatsCommandExecutor.java +++ b/src/xenon/commands/Stats.java @@ -9,6 +9,7 @@ import java.nio.file.attribute.FileTime; import java.text.CharacterIterator; import java.text.StringCharacterIterator; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -20,7 +21,7 @@ import org.bukkit.event.Listener; * * @author hanna */ -public class StatsCommandExecutor implements Listener, CommandExecutor { +public class Stats implements Listener, CommandExecutor { @Override diff --git a/src/xenon/events/AntiIllegals.java b/src/xenon/events/AntiIllegals.java index 663078b..83c004c 100644 --- a/src/xenon/events/AntiIllegals.java +++ b/src/xenon/events/AntiIllegals.java @@ -16,7 +16,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; -import xenon.Main; +import xenon.misc.Common; /** * @@ -34,7 +34,7 @@ public class AntiIllegals implements Listener { Inventory inv = p.getInventory(); revert(inv); } - }.runTaskLater(Main.getInstance(), 1); + }.runTaskLater(Common.getPlugin(), 1); } } diff --git a/src/xenon/events/AntiNetherRoof.java b/src/xenon/events/AntiNetherRoof.java index 6707706..828b55d 100644 --- a/src/xenon/events/AntiNetherRoof.java +++ b/src/xenon/events/AntiNetherRoof.java @@ -9,7 +9,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.scheduler.BukkitRunnable; -import xenon.Main; +import xenon.misc.Common; /** * @@ -47,6 +47,6 @@ public class AntiNetherRoof implements Listener { } } } - }.runTaskTimer(Main.getInstance(), 0, 20); + }.runTaskTimer(Common.getPlugin(), 0, 20); } } diff --git a/src/xenon/events/CustomMessages.java b/src/xenon/events/CustomMessages.java index 345387f..bce3235 100644 --- a/src/xenon/events/CustomMessages.java +++ b/src/xenon/events/CustomMessages.java @@ -2,7 +2,7 @@ package xenon.events; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.PlayerDeathEvent​; import org.bukkit.event.player.PlayerJoinEvent; /** @@ -11,7 +11,7 @@ import org.bukkit.event.player.PlayerJoinEvent; */ public class CustomMessages implements Listener { @EventHandler - public void PlayerDeathEvent​(PlayerDeathEvent event) { + public void PlayerDeathEvent​(PlayerDeathEvent​ event) { String pName = event.getEntity().getName(); String dMessage = event.getDeathMessage().replace(pName + " ", ""); event.setDeathMessage(String.format("§d%s §b%s",pName, dMessage)); diff --git a/src/xenon/events/CustomTab.java b/src/xenon/events/CustomTab.java index 74c8434..8f78ea1 100644 --- a/src/xenon/events/CustomTab.java +++ b/src/xenon/events/CustomTab.java @@ -6,15 +6,14 @@ package xenon.events; import java.lang.reflect.Field; - -import net.minecraft.server.v1_16_R1.ChatComponentText; -import net.minecraft.server.v1_16_R1.MinecraftServer; -import net.minecraft.server.v1_16_R1.PacketPlayOutPlayerListHeaderFooter; +import net.minecraft.server.v1_16_R3.ChatComponentText; +import net.minecraft.server.v1_16_R3.MinecraftServer; +import net.minecraft.server.v1_16_R3.PacketPlayOutPlayerListHeaderFooter; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import xenon.Main; +import xenon.misc.Common; import xenon.misc.GetElapsedTime; /** @@ -74,6 +73,6 @@ public class CustomTab { } - }.runTaskTimer(Main.getInstance(), 0, 20); + }.runTaskTimer(Common.getPlugin(), 0, 20); } } diff --git a/src/xenon/events/ElytraflyPatch.java b/src/xenon/events/ElytraflyPatch.java index c4606ec..6c7274a 100644 --- a/src/xenon/events/ElytraflyPatch.java +++ b/src/xenon/events/ElytraflyPatch.java @@ -9,7 +9,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scheduler.BukkitRunnable; -import xenon.Main; +import xenon.misc.Common; /** * @@ -40,7 +40,7 @@ public class ElytraflyPatch implements Listener { Location curLocation = p.getLocation(); double curDistanceFlown = curLocation.distanceSquared(prevLocation); - if (p.isGliding() && !p.getLocation().getBlock().isLiquid()) { + if (p.isGliding() && !p.isInWater()) { if (glideStarted == null) glideStarted = curLocation; if (distancesFlown.size() == 10) { @@ -69,7 +69,7 @@ public class ElytraflyPatch implements Listener { prevLocation = curLocation; } - }.runTaskTimer(Main.getInstance(), 0, 3); + }.runTaskTimer(Common.getPlugin(), 0, 3); } } diff --git a/src/xenon/events/LimitArmorStands.java b/src/xenon/events/LimitArmorStands.java index 4362502..c6e2b09 100644 --- a/src/xenon/events/LimitArmorStands.java +++ b/src/xenon/events/LimitArmorStands.java @@ -7,7 +7,7 @@ import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitRunnable; -import xenon.Main; +import xenon.misc.Common; /** * @@ -32,6 +32,6 @@ public class LimitArmorStands { } } - }}.runTaskTimer(Main.getInstance(), 0, 20); + }}.runTaskTimer(Common.getPlugin(), 0, 20); } } diff --git a/src/xenon/main.java b/src/xenon/main.java new file mode 100644 index 0000000..20942d1 --- /dev/null +++ b/src/xenon/main.java @@ -0,0 +1,51 @@ +package xenon; + + + +import xenon.commands.Discord; +import xenon.commands.Help; +import xenon.commands.Stats; +import xenon.commands.Joindate; +import xenon.commands.Kill; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; +import xenon.events.AntiIllegals; +import xenon.events.AntiNetherRoof; +import xenon.events.AntiSpam; +import xenon.events.BoatflyPatch; +import xenon.events.CustomChat; +import xenon.events.CustomMessages; +import xenon.events.CustomTab; +import xenon.events.ElytraflyPatch; +import xenon.events.LimitArmorStands; +import xenon.events.RandomRespawn; + +/** + * + * @author hanna + */ + + public class main extends JavaPlugin implements Listener { + + @Override + public void onEnable() { + getServer().getPluginManager().registerEvents(new AntiIllegals(), this); + getServer().getPluginManager().registerEvents(new AntiNetherRoof(), this); + getServer().getPluginManager().registerEvents(new AntiSpam(), this); + getServer().getPluginManager().registerEvents(new BoatflyPatch(), this); + getServer().getPluginManager().registerEvents(new CustomChat(), this); + getServer().getPluginManager().registerEvents(new CustomMessages(), this); + getServer().getPluginManager().registerEvents(new ElytraflyPatch(), this); + getServer().getPluginManager().registerEvents(new RandomRespawn(), this); + + LimitArmorStands.limit(); + CustomTab.tab(); + + this.getCommand("kill").setExecutor(new Kill()); + this.getCommand("help").setExecutor(new Help()); + this.getCommand("discord").setExecutor(new Discord()); + this.getCommand("stats").setExecutor(new Stats()); + this.getCommand("joindate").setExecutor(new Joindate()); + + } +} \ No newline at end of file diff --git a/src/xenon/misc/Common.java b/src/xenon/misc/Common.java new file mode 100644 index 0000000..376ac3e --- /dev/null +++ b/src/xenon/misc/Common.java @@ -0,0 +1,14 @@ +package xenon.misc; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +/** + * + * @author hanna + */ +public class Common { + public static Plugin getPlugin() { + return Bukkit.getServer().getPluginManager().getPlugin("xenon"); + } +} diff --git a/src/xenon/misc/Config.java b/src/xenon/misc/Config.java deleted file mode 100644 index 412a791..0000000 --- a/src/xenon/misc/Config.java +++ /dev/null @@ -1,60 +0,0 @@ -package xenon.misc; - -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.io.IOException; - -public class Config { - - private final File file; - private final YamlConfiguration config; - - public Config() { - File dir = new File("./plugins/Xenon"); - - if (!dir.exists()) { - dir.mkdirs(); - } - - this.file = new File(dir, "config.yml"); - - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - this.config = YamlConfiguration.loadConfiguration(file); - } - - public File getFile() { - return file; - } - - public YamlConfiguration getConfig() { - return config; - } - - public void save() { - try { - config.save(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void reload(){ - try { - config.load(file); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - - } -}