13
0

Create a copy schem for automatic clipboard saving

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-06-25 16:19:37 +02:00
Ursprung 30f5a3430b
Commit e40b419e2e
2 geänderte Dateien mit 50 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,48 @@
package de.steamwar.schematicsystem;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.io.IOException;
import java.util.UUID;
public class ClipboardListener implements Listener {
private static final String CLIPBOARD_SCHEMNAME = "//copy";
@EventHandler
public void onLogin(PlayerJoinEvent e){
Schematic schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, e.getPlayer().getUniqueId());
if(schematic != null){
try {
schematic.loadToPlayer(e.getPlayer());
} catch (IOException | NoClipboardException ex) {
//ignore
}
}
}
@EventHandler
public void onLogout(PlayerQuitEvent e){
UUID playerUUID = e.getPlayer().getUniqueId();
Schematic schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, playerUUID);
boolean newSchem = false;
if(schematic == null){
Schematic.createSchem(CLIPBOARD_SCHEMNAME, playerUUID, "", SchematicType.Normal);
schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, playerUUID);
newSchem = true;
}
try{
schematic.saveFromPlayer(e.getPlayer());
} catch (IOException | NoClipboardException ex) {
if(newSchem)
schematic.remove();
}
}
}

Datei anzeigen

@ -29,5 +29,7 @@ public class SchematicSystem extends JavaPlugin {
CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem"); CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem");
getCommand("schem").setExecutor(new SchematicCommand()); getCommand("schem").setExecutor(new SchematicCommand());
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
} }
} }