commit 1de9dc06005174286f88a000b8a1f6176e04bfaf Author: Simon Giesel Date: Fri Sep 20 00:04:36 2019 +0200 Initial commit Signed-off-by: Simon diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..697fb76 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/simon.xml b/.idea/dictionaries/simon.xml new file mode 100644 index 0000000..e8a0378 --- /dev/null +++ b/.idea/dictionaries/simon.xml @@ -0,0 +1,7 @@ + + + + cliffbreak + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4b661a5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CliffbreakCore.iml b/CliffbreakCore.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/CliffbreakCore.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ccb07c6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + de.cliffbreak.core + CliffbreakCore + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + + + + UTF-8 + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + org.spigotmc + spigot-api + 1.13-R0.1-SNAPSHOT + provided + + + \ No newline at end of file diff --git a/src/main/java/de/cliffbreak/core/CliffbreakCore.java b/src/main/java/de/cliffbreak/core/CliffbreakCore.java new file mode 100644 index 0000000..4b0f0af --- /dev/null +++ b/src/main/java/de/cliffbreak/core/CliffbreakCore.java @@ -0,0 +1,27 @@ +package de.cliffbreak.core; + +import de.cliffbreak.core.commands.CommandGM; +import de.cliffbreak.core.commands.CommandHub; +import de.cliffbreak.core.commands.CommandSpeed; +import de.cliffbreak.core.listeners.ChatListener; +import de.cliffbreak.core.listeners.PlayerJoinListener; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; + +public class CliffbreakCore extends JavaPlugin { + + public File cfgFile = new File("plugins/Core", "config.yml"); + public FileConfiguration cfg = YamlConfiguration.loadConfiguration(cfgFile); + + @Override + public void onEnable() { + getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this); + getServer().getPluginManager().registerEvents(new ChatListener(), this); + this.getCommand("gm").setExecutor(new CommandGM()); + this.getCommand("speed").setExecutor(new CommandSpeed()); + this.getCommand("hub").setExecutor(new CommandHub(this)); + } +} diff --git a/src/main/java/de/cliffbreak/core/commands/CommandGM.java b/src/main/java/de/cliffbreak/core/commands/CommandGM.java new file mode 100644 index 0000000..0af424b --- /dev/null +++ b/src/main/java/de/cliffbreak/core/commands/CommandGM.java @@ -0,0 +1,24 @@ +package de.cliffbreak.core.commands; + +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandGM implements CommandExecutor { + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (commandSender instanceof Player) { + Player p = (Player) commandSender; + if (!p.hasPermission("cliffbreak.command.gm")) { + p.sendMessage("§cNope"); + return true; + } + if (p.getGameMode() == GameMode.CREATIVE) + p.setGameMode(GameMode.SURVIVAL); + else p.setGameMode(GameMode.CREATIVE); + } + return true; + } +} diff --git a/src/main/java/de/cliffbreak/core/commands/CommandHub.java b/src/main/java/de/cliffbreak/core/commands/CommandHub.java new file mode 100644 index 0000000..e2642ab --- /dev/null +++ b/src/main/java/de/cliffbreak/core/commands/CommandHub.java @@ -0,0 +1,63 @@ +package de.cliffbreak.core.commands; + +import de.cliffbreak.core.CliffbreakCore; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.IOException; + +public class CommandHub implements CommandExecutor { + + private CliffbreakCore plugin; + + public CommandHub(CliffbreakCore plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (commandSender instanceof Player) { + Player p = (Player) commandSender; + + if (args.length == 0) { + World w = Bukkit.getWorld(plugin.cfg.getString("Hub.Spawn.World")); + double x = plugin.cfg.getDouble("Hub.Spawn.X"); + double y = plugin.cfg.getDouble("Hub.Spawn.Y"); + double z = plugin.cfg.getDouble("Hub.Spawn.Z"); + float yaw = (float) plugin.cfg.getDouble("Hub.Spawn.Yaw"); + float pitch = (float) plugin.cfg.getDouble("Hub.Spawn.Pitch"); + + p.teleport(new Location(w, x, y, z, yaw, pitch)); + return true; + } + + if (!p.hasPermission("cliffbreak.command.hub")) { + p.sendMessage("§cNope"); + return true; + } + if (args.length == 1 && args[0].equalsIgnoreCase("setspawn")) { + plugin.cfg.set("Hub.Spawn.World", p.getLocation().getWorld().getName()); + plugin.cfg.set("Hub.Spawn.X", p.getLocation().getX()); + plugin.cfg.set("Hub.Spawn.Y", p.getLocation().getY()); + plugin.cfg.set("Hub.Spawn.Z", p.getLocation().getZ()); + plugin.cfg.set("Hub.Spawn.Yaw", (double) p.getLocation().getYaw()); + plugin.cfg.set("Hub.Spawn.Pitch", (double) p.getLocation().getPitch()); + + try { + plugin.cfg.save(plugin.cfgFile); + p.sendMessage("§aDer §lHub-Spawn §r§awurde erfolgreich gesetzt."); + } catch (IOException e) { + p.sendMessage("§cDer §lHub-Spawn §r§cwurde NICHT erfolgreich gesetzt."); + e.printStackTrace(); + } + return true; + } + } + return true; + } +} diff --git a/src/main/java/de/cliffbreak/core/commands/CommandSpeed.java b/src/main/java/de/cliffbreak/core/commands/CommandSpeed.java new file mode 100644 index 0000000..595fe0a --- /dev/null +++ b/src/main/java/de/cliffbreak/core/commands/CommandSpeed.java @@ -0,0 +1,32 @@ +package de.cliffbreak.core.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandSpeed implements CommandExecutor { + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (commandSender instanceof Player) { + Player p = (Player) commandSender; + if (!p.hasPermission("cliffbreak.command.speed")) { + p.sendMessage("§cNope"); + return true; + } + if (strings.length == 0) + p.setFlySpeed(0.1f); + else + try { + int speed = Integer.parseInt(strings[0]); + if (speed < 0 || speed > 10) + p.sendMessage("§c§lFehler: §rDas Argument muss zwischen 0 und 10 liegen."); + else + p.setFlySpeed(speed / 10f); + } catch (NumberFormatException ex) { + p.sendMessage("§c§lFehler: §rDas Argument muss zwischen 0 und 10 liegen."); + } + } + return true; + } +} diff --git a/src/main/java/de/cliffbreak/core/listeners/ChatListener.java b/src/main/java/de/cliffbreak/core/listeners/ChatListener.java new file mode 100644 index 0000000..755a006 --- /dev/null +++ b/src/main/java/de/cliffbreak/core/listeners/ChatListener.java @@ -0,0 +1,25 @@ +package de.cliffbreak.core.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.Calendar; +import java.util.Date; + +public class ChatListener implements Listener { + + @EventHandler() + public void onChat(AsyncPlayerChatEvent e) { + e.setCancelled(true); + Calendar calendar = Calendar.getInstance(); + Date date = calendar.getTime(); + String timestamp = String.format("%02d", date.getHours()) + ":" + String.format("%02d", date.getMinutes()); + for (Player all : Bukkit.getOnlinePlayers()) { + all.sendMessage(" §8" + timestamp + " §7| §b" + e.getPlayer().getName() + " §7>> §f" + e.getMessage()); + } + } +} + diff --git a/src/main/java/de/cliffbreak/core/listeners/PlayerJoinListener.java b/src/main/java/de/cliffbreak/core/listeners/PlayerJoinListener.java new file mode 100644 index 0000000..556baad --- /dev/null +++ b/src/main/java/de/cliffbreak/core/listeners/PlayerJoinListener.java @@ -0,0 +1,38 @@ +package de.cliffbreak.core.listeners; + +import de.cliffbreak.core.CliffbreakCore; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class PlayerJoinListener implements Listener { + private CliffbreakCore plugin; + + public PlayerJoinListener(CliffbreakCore plugin) { + this.plugin = plugin; + } + + @EventHandler() + public void onPlayerJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + e.setJoinMessage(null); + + World w = Bukkit.getWorld(plugin.cfg.getString("Hub.Spawn.World")); + double x = plugin.cfg.getDouble("Hub.Spawn.X"); + double y = plugin.cfg.getDouble("Hub.Spawn.Y"); + double z = plugin.cfg.getDouble("Hub.Spawn.Z"); + float yaw = (float) plugin.cfg.getDouble("Hub.Spawn.Yaw"); + float pitch = (float) plugin.cfg.getDouble("Hub.Spawn.Pitch"); + p.teleport(new Location(w, x, y, z, yaw, pitch)); + + p.setFlySpeed(0.1f); + p.setAllowFlight(false); + p.setFlying(false); + p.setGameMode(GameMode.ADVENTURE); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..b161c6b --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,14 @@ +name: CliffbreakCore +version: 0.1 +main: de.cliffbreak.core.CliffbreakCore +api-version: 1.14 +commands: + gm: + description: Change GameMode to creative or survival + usage: /gm + speed: + description: Change FlyingSpeed + usage: /speed + hub: + description: Default Hub Command + usage: /hub \ No newline at end of file