From 1c7ab28a77743aba062dd370957000513852ea6d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 5 Aug 2024 09:56:54 +0200 Subject: [PATCH] Add TutorialSystem module --- TutorialSystem/build.gradle.kts | 62 +++++++++++++++++++ .../de/steamwar/tutorial/TutorialSystem.java | 51 +++++++++++++++ .../tutorial/commands/BookReplaceCommand.java | 48 ++++++++++++++ .../tutorial/commands/TutorialCommand.java | 23 +++++++ .../tutorial/commands/UnsignCommand.java | 21 +++++++ .../tutorial/listener/BasicListener.java | 31 ++++++++++ .../steamwar/tutorial/listener/Joining.java | 40 ++++++++++++ .../steamwar/tutorial/listener/RateSign.java | 48 ++++++++++++++ TutorialSystem/src/plugin.yml | 7 +++ settings.gradle.kts | 2 + 10 files changed, 333 insertions(+) create mode 100644 TutorialSystem/build.gradle.kts create mode 100644 TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java create mode 100644 TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java create mode 100644 TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java create mode 100644 TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java create mode 100644 TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java create mode 100644 TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java create mode 100644 TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java create mode 100644 TutorialSystem/src/plugin.yml diff --git a/TutorialSystem/build.gradle.kts b/TutorialSystem/build.gradle.kts new file mode 100644 index 00000000..34f36246 --- /dev/null +++ b/TutorialSystem/build.gradle.kts @@ -0,0 +1,62 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +plugins { + id("java") + id("base") + + id("com.github.johnrengelman.shadow") +} + +group = "de.steamwar" +version = "" + +tasks.compileJava { + options.encoding = "UTF-8" +} + +tasks.build { + finalizedBy(tasks.shadowJar) +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +sourceSets { + main { + java { + srcDirs("src/") + } + resources { + srcDirs("src/") + exclude("**/*.java", "**/*.kt") + } + } +} + +dependencies { + compileOnly("org.projectlombok:lombok:1.18.32") + annotationProcessor("org.projectlombok:lombok:1.18.32") + + compileOnly(project(":SpigotCore")) + + compileOnly("de.steamwar:spigot:1.15") +} diff --git a/TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java b/TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java new file mode 100644 index 00000000..a261375f --- /dev/null +++ b/TutorialSystem/src/de/steamwar/tutorial/TutorialSystem.java @@ -0,0 +1,51 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.tutorial; + +import de.steamwar.tutorial.commands.BookReplaceCommand; +import de.steamwar.tutorial.commands.TutorialCommand; +import de.steamwar.tutorial.commands.UnsignCommand; +import de.steamwar.tutorial.listener.Joining; +import de.steamwar.tutorial.listener.RateSign; +import org.bukkit.plugin.java.JavaPlugin; + +public class TutorialSystem extends JavaPlugin { + + private static TutorialSystem plugin; + + @Override + public void onLoad() { + plugin = this; + } + + @Override + public void onEnable() { + new RateSign(); + new Joining(); + + new BookReplaceCommand(); + new TutorialCommand(); + new UnsignCommand(); + } + + public static TutorialSystem getPlugin() { + return plugin; + } +} diff --git a/TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java b/TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java new file mode 100644 index 00000000..46f6008f --- /dev/null +++ b/TutorialSystem/src/de/steamwar/tutorial/commands/BookReplaceCommand.java @@ -0,0 +1,48 @@ +package de.steamwar.tutorial.commands; + +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.List; + +public class BookReplaceCommand extends SWCommand { + + public BookReplaceCommand() { + super("bookreplace"); + } + + @Register("color") + public void color(Player player) { + ItemStack itemStack = player.getInventory().getItemInMainHand(); + ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta instanceof BookMeta) { + BookMeta bookMeta = (BookMeta) itemMeta; + replace(bookMeta, '&', '§'); + itemStack.setItemMeta(bookMeta); + player.getInventory().setItemInMainHand(itemStack); + } + } + + @Register("uncolor") + public void uncolor(Player player) { + ItemStack itemStack = player.getInventory().getItemInMainHand(); + ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta instanceof BookMeta) { + BookMeta bookMeta = (BookMeta) itemMeta; + replace(bookMeta, '§', '&'); + itemStack.setItemMeta(bookMeta); + player.getInventory().setItemInMainHand(itemStack); + } + } + + private void replace(BookMeta bookMeta, char oldChar, char newChar) { + List stringList = bookMeta.getPages(); + for (int i = 0; i < stringList.size(); i++) { + String string = stringList.get(i); + bookMeta.setPage(i + 1, string.replace(oldChar, newChar)); + } + } +} diff --git a/TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java b/TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java new file mode 100644 index 00000000..f3824d96 --- /dev/null +++ b/TutorialSystem/src/de/steamwar/tutorial/commands/TutorialCommand.java @@ -0,0 +1,23 @@ +package de.steamwar.tutorial.commands; + +import de.steamwar.command.SWCommand; +import de.steamwar.network.NetworkSender; +import de.steamwar.network.packets.client.ExecuteCommandPacket; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.entity.Player; + +public class TutorialCommand extends SWCommand { + + public TutorialCommand() { + super("tutorial"); + } + + @Register("rate") + public void rateCommand(Player player) { + rate(player); + } + + public static void rate(Player player) { + NetworkSender.send(new ExecuteCommandPacket(SteamwarUser.get(player.getUniqueId()).getId(), "tutorial rate " + System.getProperty("tutorial"))); + } +} diff --git a/TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java b/TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java new file mode 100644 index 00000000..847db16f --- /dev/null +++ b/TutorialSystem/src/de/steamwar/tutorial/commands/UnsignCommand.java @@ -0,0 +1,21 @@ +package de.steamwar.tutorial.commands; + +import de.steamwar.command.SWCommand; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class UnsignCommand extends SWCommand { + + public UnsignCommand() { + super("unsign"); + } + + @Register + public void unsignCommand(Player p) { + ItemStack itemStack = p.getInventory().getItemInMainHand(); + if (itemStack.getType() != Material.WRITTEN_BOOK) return; + itemStack.setType(Material.WRITABLE_BOOK); + p.getInventory().setItemInMainHand(itemStack); + } +} diff --git a/TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java b/TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java new file mode 100644 index 00000000..4ef5f8c7 --- /dev/null +++ b/TutorialSystem/src/de/steamwar/tutorial/listener/BasicListener.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.tutorial.listener; + +import de.steamwar.tutorial.TutorialSystem; +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; + +public abstract class BasicListener implements Listener { + + public BasicListener() { + Bukkit.getPluginManager().registerEvents(this, TutorialSystem.getPlugin()); + } +} diff --git a/TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java b/TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java new file mode 100644 index 00000000..d347a262 --- /dev/null +++ b/TutorialSystem/src/de/steamwar/tutorial/listener/Joining.java @@ -0,0 +1,40 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.tutorial.listener; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class Joining extends BasicListener { + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + event.getPlayer().setOp(true); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) { + Bukkit.shutdown(); + } + } +} diff --git a/TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java b/TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java new file mode 100644 index 00000000..01d87505 --- /dev/null +++ b/TutorialSystem/src/de/steamwar/tutorial/listener/RateSign.java @@ -0,0 +1,48 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.tutorial.listener; + +import de.steamwar.tutorial.commands.TutorialCommand; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class RateSign extends BasicListener { + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if(!event.hasBlock() || event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + + BlockState state = event.getClickedBlock().getState(); + if (!(state instanceof Sign)) + return; + + Sign sign = (Sign) state; + if(!"[rate]".equals(sign.getLine(0))) + return; + + Player player = event.getPlayer(); + TutorialCommand.rate(player); + } +} diff --git a/TutorialSystem/src/plugin.yml b/TutorialSystem/src/plugin.yml new file mode 100644 index 00000000..8534f043 --- /dev/null +++ b/TutorialSystem/src/plugin.yml @@ -0,0 +1,7 @@ +name: TutorialSystem +version: "1.0" +authors: + - Lixfel +main: de.steamwar.tutorial.TutorialSystem +depend: [SpigotCore] +api-version: "1.13" diff --git a/settings.gradle.kts b/settings.gradle.kts index d14c9b12..9e83bc5a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -47,5 +47,7 @@ include("Teamserver") include("TowerRun") +include("TutorialSystem") + include("VelocityCore") include("VelocityCore:Persistent")