Add TutorialSystem module

This commit is contained in:
2024-08-05 09:56:54 +02:00
parent 48eb071c26
commit 1c7ab28a77
10 changed files with 333 additions and 0 deletions
+62
View File
@@ -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 <https://www.gnu.org/licenses/>.
*/
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")
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}
@@ -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<String> stringList = bookMeta.getPages();
for (int i = 0; i < stringList.size(); i++) {
String string = stringList.get(i);
bookMeta.setPage(i + 1, string.replace(oldChar, newChar));
}
}
}
@@ -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")));
}
}
@@ -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);
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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());
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}
+7
View File
@@ -0,0 +1,7 @@
name: TutorialSystem
version: "1.0"
authors:
- Lixfel
main: de.steamwar.tutorial.TutorialSystem
depend: [SpigotCore]
api-version: "1.13"
+2
View File
@@ -47,5 +47,7 @@ include("Teamserver")
include("TowerRun")
include("TutorialSystem")
include("VelocityCore")
include("VelocityCore:Persistent")