SteamWar/BauSystem
Archiviert
13
0

Refactoring for new Core

Dieser Commit ist enthalten in:
Lixfel 2019-11-10 17:29:01 +01:00
Ursprung 8e91113f3d
Commit be7e5acec5
14 geänderte Dateien mit 62 neuen und 213 gelöschten Zeilen

Datei anzeigen

@ -15,7 +15,7 @@
<repositories> <repositories>
<repository> <repository>
<id>maven</id> <id>maven</id>
<url>https://steamwar.de:81/maven/</url> <url>https://steamwar.de/maven/</url>
</repository> </repository>
</repositories> </repositories>
@ -52,7 +52,7 @@
<dependency> <dependency>
<groupId>steamwar</groupId> <groupId>steamwar</groupId>
<artifactId>SpigotCore</artifactId> <artifactId>SpigotCore</artifactId>
<version>1.0</version> <version>2.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

Datei anzeigen

@ -4,7 +4,8 @@ import de.steamwar.bausystem.commands.*;
import de.steamwar.bausystem.world.ArenaSection; import de.steamwar.bausystem.world.ArenaSection;
import de.steamwar.bausystem.world.RegionListener; import de.steamwar.bausystem.world.RegionListener;
import de.steamwar.bausystem.world.TNTListener; import de.steamwar.bausystem.world.TNTListener;
import de.warking.hunjy.MySQL.WarkingUser; import de.steamwar.core.CommandRemover;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -43,9 +44,9 @@ public class BauSystem extends JavaPlugin implements Listener {
try { try {
CommandRemover.removeAll("tp", "gamemode", "time"); CommandRemover.removeAll("tp", "gamemode", "time");
CommandRemover.injectCommand(new CommandTeleport()); CommandInjector.injectCommand(new CommandTeleport());
CommandRemover.injectCommand(new CommandGamemode()); CommandInjector.injectCommand(new CommandGamemode());
CommandRemover.injectCommand(new CommandTime()); CommandInjector.injectCommand(new CommandTime());
} catch (Exception e) { } catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to replace commands", e); getLogger().log(Level.SEVERE, "Failed to replace commands", e);
Bukkit.shutdown(); Bukkit.shutdown();
@ -89,7 +90,7 @@ public class BauSystem extends JavaPlugin implements Listener {
return sections; return sections;
} }
public static int getOwnerID(){ public static int getOwnerID(){
return WarkingUser.get(owner).getId(); return SteamwarUser.get(owner).getId();
} }
@EventHandler @EventHandler

Datei anzeigen

@ -1,55 +1,53 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.sql.BauweltMember;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import de.warking.hunjy.MySQL.WarkingUser; import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID;
public class CommandBau implements CommandExecutor { public class CommandBau implements CommandExecutor {
private void onToggleBD(Player p, String arg) { private void onToggleBD(Player p, String arg) {
UUID id = WarkingUser.get(arg).getUUID(); SteamwarUser id = SteamwarUser.get(arg);
if(negativeToggleCheck(p, id)){ if(negativeToggleCheck(p, id)){
return; return;
} }
BauweltMember target = BauweltMember.getBauMember(id); BauweltMember target = BauweltMember.getBauMember(BauSystem.getOwnerID(), id.getId());
Welt.toggleBuild(p, target); Welt.toggleBuild(p, target);
} }
private void onToggleWE(Player p, String arg) { private void onToggleWE(Player p, String arg) {
UUID id = WarkingUser.get(arg).getUUID(); SteamwarUser id = SteamwarUser.get(arg);
if(negativeToggleCheck(p, id)){ if(negativeToggleCheck(p, id)){
return; return;
} }
BauweltMember target = BauweltMember.getBauMember(id); BauweltMember target = BauweltMember.getBauMember(BauSystem.getOwnerID(), id.getId());
Welt.toggleWE(p, target); Welt.toggleWE(p, target);
} }
private void onToggleWorld(Player p, String arg) { private void onToggleWorld(Player p, String arg) {
UUID id = WarkingUser.get(arg).getUUID(); SteamwarUser id = SteamwarUser.get(arg);
if(negativeToggleCheck(p, id)){ if(negativeToggleCheck(p, id)){
return; return;
} }
BauweltMember target = BauweltMember.getBauMember(id); BauweltMember target = BauweltMember.getBauMember(BauSystem.getOwnerID(), id.getId());
Welt.toggleWorld(p, target); Welt.toggleWorld(p, target);
} }
private boolean negativeToggleCheck(Player p, UUID id){ private boolean negativeToggleCheck(Player p, SteamwarUser id){
if (id == null) { if (id == null) {
p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spieler"); p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spieler");
return true; return true;
} }
BauweltMember target = BauweltMember.getBauMember(id); BauweltMember target = BauweltMember.getBauMember(BauSystem.getOwnerID(), id.getId());
if (target == null) { if (target == null) {
p.sendMessage(BauSystem.PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt!"); p.sendMessage(BauSystem.PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt!");
return true; return true;

Datei anzeigen

@ -2,7 +2,7 @@ package de.steamwar.bausystem.commands;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -37,7 +37,7 @@ public class CommandGamemode extends BukkitCommand {
Player p = (Player) sender; Player p = (Player) sender;
if(!p.getUniqueId().equals(BauSystem.getOwner())){ if(!p.getUniqueId().equals(BauSystem.getOwner())){
BauweltMember member = BauweltMember.getBauMember(p.getUniqueId()); BauweltMember member = BauweltMember.getBauMember(BauSystem.getOwner(), p.getUniqueId());
if(member == null || !member.isBuild()){ if(member == null || !member.isBuild()){
p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier deinen Spielmodus nicht ändern"); p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier deinen Spielmodus nicht ändern");
return false; return false;
@ -55,6 +55,7 @@ public class CommandGamemode extends BukkitCommand {
return true; return true;
} }
@SuppressWarnings("deprecation")
private GameMode createMode(String modeArg){ private GameMode createMode(String modeArg){
try { try {
return GameMode.getByValue(Integer.parseInt(modeArg)); return GameMode.getByValue(Integer.parseInt(modeArg));
@ -76,8 +77,8 @@ public class CommandGamemode extends BukkitCommand {
Validate.notNull(alias, "Alias cannot be null"); Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) if (args.length == 1)
return ((List) StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES, return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES,
new ArrayList(GAMEMODE_NAMES.size()))); new ArrayList<>(GAMEMODE_NAMES.size()));
if (args.length == 2) { if (args.length == 2) {
return super.tabComplete(sender, alias, args); return super.tabComplete(sender, alias, args);
} }

Datei anzeigen

@ -1,8 +1,8 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import de.warking.hunjy.MySQL.WarkingUser; import de.steamwar.sql.SteamwarUser;
import net.minecraft.server.v1_12_R1.MinecraftServer; import net.minecraft.server.v1_12_R1.MinecraftServer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -13,8 +13,9 @@ import java.util.List;
public class CommandInfo implements CommandExecutor { public class CommandInfo implements CommandExecutor {
@Override @Override
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + WarkingUser.get(BauSystem.getOwnerID()).getUserName()); sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getInstance().isOn() ? "§aAUS" : "§cAN"));
sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN"));
sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN"));
@ -23,7 +24,7 @@ public class CommandInfo implements CommandExecutor {
StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: ");
for (BauweltMember member : members) { for (BauweltMember member : members) {
membermessage.append("§e").append(WarkingUser.get(member.getMemberID()).getUserName()).append("§8["); membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()).append("§8[");
membermessage.append(member.isBuild() ? "§a" : "§c").append("B").append("§8,"); membermessage.append(member.isBuild() ? "§a" : "§c").append("B").append("§8,");
membermessage.append(member.isWorldEdit() ? "§a" : "§c").append("WE").append("§8,"); membermessage.append(member.isWorldEdit() ? "§a" : "§c").append("WE").append("§8,");
membermessage.append(member.isWorld() ? "§a" : "§c").append("W").append("§8]").append(" "); membermessage.append(member.isWorld() ? "§a" : "§c").append("W").append("§8]").append(" ");

Datei anzeigen

@ -0,0 +1,24 @@
package de.steamwar.bausystem.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
import java.lang.reflect.Field;
public class CommandInjector {
private CommandInjector(){}
private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName();
private static final String VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf('.') + 1);
public static void injectCommand(Command cmd) throws Exception {
Class serverClass = Class.forName("org.bukkit.craftbukkit." + VERSION + ".CraftServer");
Field f1 = serverClass.getDeclaredField("commandMap");
f1.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
commandMap.register("BauSystem", cmd);
}
}

Datei anzeigen

@ -1,43 +0,0 @@
package de.steamwar.bausystem.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
import java.lang.reflect.Field;
import java.util.Map;
public class CommandRemover {
private CommandRemover(){}
private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName();
private static final String VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf('.') + 1);
public static void removeAll(String... cmds) throws Exception {
for (String cmd : cmds) removeCommand(cmd);
}
private static void removeCommand(String command) throws Exception {
Class<?> serverClass = Class.forName("org.bukkit.craftbukkit." + VERSION + ".CraftServer");
Field f1 = serverClass.getDeclaredField("commandMap");
f1.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
Field f2 = SimpleCommandMap.class.getDeclaredField("knownCommands");
f2.setAccessible(true);
Map<String, Command> knownCommands = (Map<String, Command>) f2.get(commandMap);
knownCommands.remove(command.toLowerCase());
}
public static void injectCommand(Command cmd) throws Exception {
Class serverClass = Class.forName("org.bukkit.craftbukkit." + VERSION + ".CraftServer");
Field f1 = serverClass.getDeclaredField("commandMap");
f1.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
commandMap.register("BauSystem", cmd);
}
}

Datei anzeigen

@ -12,6 +12,7 @@ import org.bukkit.inventory.meta.SkullMeta;
public class CommandSkull implements CommandExecutor { public class CommandSkull implements CommandExecutor {
@Override @Override
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if(!(commandSender instanceof Player)) if(!(commandSender instanceof Player))
return false; return false;

Datei anzeigen

@ -1,7 +1,7 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -41,7 +41,7 @@ public class CommandTeleport extends BukkitCommand {
} }
if(!BauSystem.getOwner().equals(p.getUniqueId())){ if(!BauSystem.getOwner().equals(p.getUniqueId())){
BauweltMember member = BauweltMember.getBauMember(p.getUniqueId()); BauweltMember member = BauweltMember.getBauMember(BauSystem.getOwner(), p.getUniqueId());
if(member == null || !member.isBuild()){ if(member == null || !member.isBuild()){
p.sendMessage(BauSystem.PREFIX + "§cDu darfst dich auf dieser Welt nicht teleportieren!"); p.sendMessage(BauSystem.PREFIX + "§cDu darfst dich auf dieser Welt nicht teleportieren!");
return false; return false;

Datei anzeigen

@ -1,136 +0,0 @@
package de.steamwar.bausystem.sql;
import de.steamwar.bausystem.BauSystem;
import de.warking.hunjy.MySQL.MySQL;
import de.warking.hunjy.MySQL.WarkingUser;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static de.warking.hunjy.Core.sql;
public class BauweltMember{
private final int BauweltID;
private final int MemberID;
private boolean Build;
private boolean WorldEdit;
private boolean World;
private static final List<BauweltMember> members = new ArrayList<>();
private BauweltMember(int memberID, boolean build, boolean worldEdit, boolean world, boolean updateDB){
BauweltID = BauSystem.getOwnerID();
MemberID = memberID;
Build = build;
WorldEdit = worldEdit;
World = world;
if(updateDB)
updateDB();
members.add(this);
}
public BauweltMember(int memberID, boolean build, boolean worldEdit, boolean world){
this(memberID, build, worldEdit, world, true);
}
public BauweltMember(UUID memberID, boolean build, boolean worldEdit, boolean world){
this(WarkingUser.get(memberID).getId(), build, worldEdit, world, true);
}
public void remove(){
sql.update("DELETE FROM BauweltMember WHERE BauweltID = " + BauweltID + " AND MemberID = " + MemberID);
members.remove(this);
}
private void updateDB(){
sql.update("INSERT INTO BauweltMember" +
" (BauweltID, MemberID, Build, WorldEdit, World)" +
" VALUES" +
" ('" + BauweltID + "', '" + MemberID + "', '" + MySQL.booleanToInt(Build) + "', '" + sql.booleanToInt(WorldEdit) + "', '" + sql.booleanToInt(World) + "')" +
" ON DUPLICATE KEY UPDATE" +
" Build = VALUES(Build), WorldEdit = VALUES(WorldEdit), World = VALUES(World)");
}
public static BauweltMember getBauMember(UUID memberID){
return getBauMember(WarkingUser.get(memberID).getId());
}
public static BauweltMember getBauMember(int memberID){
for(BauweltMember member : members)
if(member.MemberID == memberID)
return member;
ResultSet member = sql.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + BauSystem.getOwnerID() + "' AND MemberID = '" + memberID + "'");
try {
if(member == null || !member.next()){
return null;
}
boolean build = member.getBoolean("Build");
boolean worldEdit = member.getBoolean("WorldEdit");
boolean testblock = member.getBoolean("World");
return new BauweltMember(memberID, build, worldEdit, testblock, false);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public static List<BauweltMember> getMembers(UUID bauweltID){
return getMembers(WarkingUser.get(bauweltID).getId());
}
public static List<BauweltMember> getMembers(int bauweltID){
try{
ResultSet memberlist = sql.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "'");
List<BauweltMember> members = new ArrayList<>();
while(memberlist.next()){
int memberID = memberlist.getInt("MemberID");
boolean build = memberlist.getBoolean("Build");
boolean worldEdit = memberlist.getBoolean("WorldEdit");
boolean testblock = memberlist.getBoolean("World");
members.add(new BauweltMember(memberID, build, worldEdit, testblock, false));
}
return members;
}catch(SQLException e){
e.printStackTrace();
}
return new ArrayList<>();
}
public int getBauweltID() {
return BauweltID;
}
public int getMemberID() {
return MemberID;
}
public boolean isBuild() {
return Build;
}
public void setBuild(boolean build) {
Build = build;
updateDB();
}
public boolean isWorldEdit() {
return WorldEdit;
}
public void setWorldEdit(boolean worldEdit) {
WorldEdit = worldEdit;
updateDB();
}
public boolean isWorld() {
return World;
}
public void setWorld(boolean world) {
World = world;
updateDB();
}
}

Datei anzeigen

@ -138,6 +138,7 @@ public class AutoLoader implements Listener {
//BlockRedstoneEvent? //BlockRedstoneEvent?
@EventHandler @EventHandler
@SuppressWarnings("deprecation")
public void onPlayerInteract(PlayerInteractEvent event){ public void onPlayerInteract(PlayerInteractEvent event){
if(!setup || !event.getPlayer().equals(player)) if(!setup || !event.getPlayer().equals(player))
return; return;

Datei anzeigen

@ -13,6 +13,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.*; import java.util.*;
@SuppressWarnings("deprecation")
public class TNTTracer { public class TNTTracer {
private static final byte BRICK_STEP = new Step(Material.BRICK).getData(); private static final byte BRICK_STEP = new Step(Material.BRICK).getData();

Datei anzeigen

@ -2,8 +2,8 @@ package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import de.warking.hunjy.MySQL.WarkingUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -15,7 +15,7 @@ public class Welt {
if(member.getUniqueId().equals(BauSystem.getOwner())) if(member.getUniqueId().equals(BauSystem.getOwner()))
return false; return false;
BauweltMember member1 = BauweltMember.getBauMember(member.getUniqueId()); BauweltMember member1 = BauweltMember.getBauMember(BauSystem.getOwner(), member.getUniqueId());
if(member1 == null) if(member1 == null)
return true; return true;
@ -34,7 +34,7 @@ public class Welt {
} }
private static void sendMessages(Player p, boolean ableTo, BauweltMember target, String what){ private static void sendMessages(Player p, boolean ableTo, BauweltMember target, String what){
Player z = Bukkit.getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); Player z = Bukkit.getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
if (z != null) { if (z != null) {
if (ableTo) { if (ableTo) {
z.sendMessage(BauSystem.PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a " + what); z.sendMessage(BauSystem.PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a " + what);

Datei anzeigen

@ -1,7 +1,7 @@
name: BauSystem name: BauSystem
author: Lixfel author: Lixfel
version: 1.0 version: 1.0
depend: [WorldEdit, CoreSystem] depend: [WorldEdit, SpigotCore]
load: POSTWORLD load: POSTWORLD
main: de.steamwar.bausystem.BauSystem main: de.steamwar.bausystem.BauSystem
commands: commands: