Merge pull request 'Create a copy schem for automatic clipboard saving' (#60) from copySchem into master
Reviewed-by: Jan9103 <jan9103@steamwar.de>
Dieser Commit ist enthalten in:
Commit
7fba01b374
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -29,5 +29,7 @@ public class SchematicSystem extends JavaPlugin {
|
||||
CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem");
|
||||
|
||||
getCommand("schem").setExecutor(new SchematicCommand());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren