mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-10-31 09:33:43 +01:00 
			
		
		
		
	Nothing is implemented, but it can compile and "run" on sponge now.
This commit is contained in:
		| @@ -4,6 +4,8 @@ import com.intellectualcrafters.plot.generator.PlotGenerator; | ||||
| import com.intellectualcrafters.plot.object.PlotCluster; | ||||
| import com.intellectualcrafters.plot.object.PlotManager; | ||||
| import com.intellectualcrafters.plot.object.PlotWorld; | ||||
| import com.intellectualcrafters.plot.object.SetupObject; | ||||
|  | ||||
| import org.spongepowered.api.world.gen.WorldGenerator; | ||||
|  | ||||
| public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator>{ | ||||
| @@ -54,5 +56,10 @@ public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator>{ | ||||
|         // TODO Auto-generated method stub | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void processSetup(SetupObject object) { | ||||
|         // TODO Auto-generated method stub | ||||
|     } | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,93 @@ | ||||
| package com.plotsquared.sponge; | ||||
|  | ||||
| import java.util.UUID; | ||||
| import java.util.concurrent.ExecutionException; | ||||
|  | ||||
| import org.spongepowered.api.GameProfile; | ||||
| import org.spongepowered.api.entity.player.Player; | ||||
| import org.spongepowered.api.service.profile.GameProfileResolver; | ||||
|  | ||||
| import com.google.common.base.Charsets; | ||||
| import com.google.inject.Inject; | ||||
| import com.intellectualcrafters.plot.object.OfflinePlotPlayer; | ||||
| import com.intellectualcrafters.plot.object.PlotPlayer; | ||||
| import com.intellectualcrafters.plot.util.UUIDHandler; | ||||
| import com.intellectualcrafters.plot.uuid.UUIDWrapper; | ||||
|  | ||||
| public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper { | ||||
|  | ||||
|     public SpongeLowerOfflineUUIDWrapper() { | ||||
|         // Anything? | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UUID getUUID(final PlotPlayer player) { | ||||
|         return getUUID(player.getName()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UUID getUUID(final OfflinePlotPlayer player) { | ||||
|         return getUUID(player.getName()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) { | ||||
|         String name = UUIDHandler.getName(uuid); | ||||
|         if (name == null) { | ||||
|             try { | ||||
|                 GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get(); | ||||
|                 if (profile != null) { | ||||
|                     name = profile.getName(); | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|         } | ||||
|         if (name == null) { | ||||
|             for (GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) { | ||||
|                 if (getUUID(profile.getName()).equals(uuid)) { | ||||
|                     name = profile.getName(); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         final String username = name; | ||||
|         return new OfflinePlotPlayer() { | ||||
|             @Override | ||||
|             public boolean isOnline() { | ||||
|                 return UUIDHandler.getPlayer(uuid) != null; | ||||
|             } | ||||
|              | ||||
|             @Override | ||||
|             public UUID getUUID() { | ||||
|                 return uuid; | ||||
|             } | ||||
|              | ||||
|             @Override | ||||
|             public String getName() { | ||||
|                 return username; | ||||
|             } | ||||
|              | ||||
|             @Override | ||||
|             public long getLastPlayed() { | ||||
|              // TODO FIXME | ||||
|                 throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public Player[] getOnlinePlayers() { | ||||
|         return SpongeMain.THIS.getServer().getOnlinePlayers().toArray(new Player[0]); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UUID getUUID(final String name) { | ||||
|         return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); | ||||
|     } | ||||
|      | ||||
|     @Override | ||||
|     public OfflinePlotPlayer[] getOfflinePlayers() { | ||||
|      // TODO FIXME | ||||
|         throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|     } | ||||
| } | ||||
| @@ -9,11 +9,13 @@ import com.intellectualcrafters.plot.config.Settings; | ||||
| import com.intellectualcrafters.plot.generator.HybridUtils; | ||||
| import com.intellectualcrafters.plot.object.PlotPlayer; | ||||
| import com.intellectualcrafters.plot.util.*; | ||||
| import com.plotsquared.bukkit.listeners.APlotListener; | ||||
| import com.plotsquared.bukkit.util.SetupUtils; | ||||
| import com.intellectualcrafters.plot.uuid.UUIDWrapper; | ||||
| import com.plotsquared.listener.APlotListener; | ||||
|  | ||||
| import org.slf4j.Logger; | ||||
| import org.spongepowered.api.Game; | ||||
| import org.spongepowered.api.GameRegistry; | ||||
| import org.spongepowered.api.MinecraftVersion; | ||||
| import org.spongepowered.api.Server; | ||||
| import org.spongepowered.api.entity.player.Player; | ||||
| import org.spongepowered.api.entity.player.gamemode.GameModes; | ||||
| @@ -23,6 +25,7 @@ import org.spongepowered.api.event.state.PreInitializationEvent; | ||||
| import org.spongepowered.api.event.state.ServerAboutToStartEvent; | ||||
| import org.spongepowered.api.plugin.Plugin; | ||||
| import org.spongepowered.api.plugin.PluginContainer; | ||||
| import org.spongepowered.api.service.profile.GameProfileResolver; | ||||
| import org.spongepowered.api.world.DimensionTypes; | ||||
| import org.spongepowered.api.world.GeneratorTypes; | ||||
| import org.spongepowered.api.world.World; | ||||
| @@ -43,7 +46,33 @@ public class SpongeMain implements IPlotMain, PluginContainer { | ||||
|     @Inject private Game game; | ||||
|     private Server server; | ||||
|      | ||||
|     private GameProfileResolver resolver; | ||||
|      | ||||
|     private WorldModify modify; | ||||
|      | ||||
|     private Object plugin; | ||||
|      | ||||
|     // stuff // | ||||
|     public Logger getLogger() { | ||||
|         return logger; | ||||
|     } | ||||
|      | ||||
|     public Game getGame() { | ||||
|         return game; | ||||
|     } | ||||
|      | ||||
|     public Server getServer() { | ||||
|         return server; | ||||
|     } | ||||
|      | ||||
|     public GameProfileResolver getResolver() { | ||||
|         return resolver; | ||||
|     } | ||||
|      | ||||
|     public Object getPlugin() { | ||||
|         return this.plugin; | ||||
|     } | ||||
|     ///////// | ||||
|  | ||||
|     ////////////////////// SPONGE PLUGIN REGISTRATION //////////////////// | ||||
|     @Override | ||||
| @@ -84,27 +113,18 @@ public class SpongeMain implements IPlotMain, PluginContainer { | ||||
|     public void onServerAboutToStart(ServerAboutToStartEvent event) { | ||||
|         log("INIT"); | ||||
|         THIS = this; | ||||
|         PS.instance = new PS(this); | ||||
|          | ||||
|         // Setup metrics | ||||
|         if (Settings.METRICS) { | ||||
|             try { | ||||
|                 final SpongeMetrics metrics = new SpongeMetrics(game, this); | ||||
|                 metrics.start(); | ||||
|                 log(C.PREFIX.s() + "&6Metrics enabled."); | ||||
|             } catch (final Exception e) { | ||||
|                 log(C.PREFIX.s() + "&cFailed to load up metrics."); | ||||
|             } | ||||
|         } else { | ||||
|             log("&dUsing metrics will allow us to improve the plugin, please consider it :)"); | ||||
|         } | ||||
|         // resolver | ||||
|         resolver = game.getServiceManager().provide(GameProfileResolver.class).get(); | ||||
|         plugin = game.getPluginManager().getPlugin("PlotSquared").get().getInstance(); | ||||
|          | ||||
|         PS.instance = new PS(this); | ||||
|          | ||||
|         // Set the generators for each world... | ||||
|         server = game.getServer(); | ||||
|         Collection<World> worlds = server.getWorlds(); | ||||
|         if (worlds.size() > 0) { | ||||
|             log("INJECTING WORLDS!!!!!!!"); | ||||
|             UUIDHandler.startCaching(null); | ||||
|             for (World world : server.getWorlds()) { | ||||
|                 log("INJECTING WORLD: " + world.getName()); | ||||
|                 world.setWorldGenerator(new SpongePlotGenerator(world.getName())); | ||||
| @@ -112,31 +132,25 @@ public class SpongeMain implements IPlotMain, PluginContainer { | ||||
|         } | ||||
|          | ||||
|         ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds"); | ||||
|         for (String world : worldSection.getKeys(false)) { | ||||
|             this.modify = new WorldModify(this); | ||||
|             Game game = event.getGame(); | ||||
|             game.getRegistry().registerWorldGeneratorModifier(modify); | ||||
|             game.getRegistry().getWorldBuilder() | ||||
|             .name(world) | ||||
|             .enabled(true) | ||||
|             .loadsOnStartup(true) | ||||
|             .keepsSpawnLoaded(true) | ||||
|             .dimensionType(DimensionTypes.OVERWORLD) | ||||
|             .generator(GeneratorTypes.DEBUG) | ||||
|             .gameMode(GameModes.CREATIVE) | ||||
|             .generatorModifiers(modify) | ||||
|             .build(); | ||||
|         if (worldSection != null) { | ||||
|             for (String world : worldSection.getKeys(false)) { | ||||
|                 this.modify = new WorldModify(this); | ||||
|                 Game game = event.getGame(); | ||||
|                 game.getRegistry().registerWorldGeneratorModifier(modify); | ||||
|                 game.getRegistry().getWorldBuilder() | ||||
|                 .name(world) | ||||
|                 .enabled(true) | ||||
|                 .loadsOnStartup(true) | ||||
|                 .keepsSpawnLoaded(true) | ||||
|                 .dimensionType(DimensionTypes.OVERWORLD) | ||||
|                 .generator(GeneratorTypes.DEBUG) | ||||
|                 .gameMode(GameModes.CREATIVE) | ||||
|                 .generatorModifiers(modify) | ||||
|                 .build(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     public Logger getLogger() { | ||||
|         return logger; | ||||
|     } | ||||
|      | ||||
|     public Game getGame() { | ||||
|         return game; | ||||
|     } | ||||
|      | ||||
|     @Subscribe | ||||
|     public void onPlayerChat(PlayerChatEvent event) { | ||||
|         // This is how events sort of work? | ||||
| @@ -163,68 +177,72 @@ public class SpongeMain implements IPlotMain, PluginContainer { | ||||
|  | ||||
|     @Override | ||||
|     public int[] getPluginVersion() { | ||||
|         // TODO Auto-generated method stub | ||||
|         return null; | ||||
|         PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get(); | ||||
|         String version = plugin.getVersion(); | ||||
|         log("Checking plugin version: PlotSquared: "); | ||||
|         String[] split = version.split("\\."); | ||||
|         return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int[] getServerVersion() { | ||||
|         // TODO Auto-generated method stub | ||||
|         return null; | ||||
|         log("Checking minecraft version: Sponge: "); | ||||
|         String version = game.getPlatform().getMinecraftVersion().getName(); | ||||
|         String[] split = version.split("\\."); | ||||
|         return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public TaskManager getTaskManager() { | ||||
|         // TODO Auto-generated method stub | ||||
|         return null; | ||||
|         return new SpongeTaskManager(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void runEntityTask() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("runEntityTask is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void registerCommands() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("registerCommands is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void registerPlayerEvents() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("registerPlayerEvents is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void registerInventoryEvents() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("registerInventoryEvents is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void registerPlotPlusEvents() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("registerPlotPlusEvents is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void registerForceFieldEvents() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("registerForceFieldEvents is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void registerWorldEditEvents() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("registerWorldEditEvents is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void registerTNTListener() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         log("registerTNTListener is not implemented!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -265,8 +283,14 @@ public class SpongeMain implements IPlotMain, PluginContainer { | ||||
|  | ||||
|     @Override | ||||
|     public UUIDHandlerImplementation initUUIDHandler() { | ||||
|         // TODO Auto-generated method stub | ||||
|         return null; | ||||
|         UUIDWrapper wrapper; | ||||
|         if (Settings.OFFLINE_MODE || !PS.get().checkVersion(this.getServerVersion(), 1, 7, 6)) { | ||||
|             wrapper = new SpongeLowerOfflineUUIDWrapper(); | ||||
|         } | ||||
|         else { | ||||
|             wrapper = new SpongeOnlineUUIDWrapper(); | ||||
|         } | ||||
|         return new SpongeUUIDHandler(wrapper); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -319,14 +343,19 @@ public class SpongeMain implements IPlotMain, PluginContainer { | ||||
|  | ||||
|     @Override | ||||
|     public String getServerName() { | ||||
|         // TODO Auto-generated method stub | ||||
|         return null; | ||||
|      // TODO FIXME | ||||
|         throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void startMetrics() { | ||||
|         // TODO Auto-generated method stub | ||||
|          | ||||
|         try { | ||||
|             final SpongeMetrics metrics = new SpongeMetrics(game, this); | ||||
|             metrics.start(); | ||||
|             log(C.PREFIX.s() + "&6Metrics enabled."); | ||||
|         } catch (final Exception e) { | ||||
|             log(C.PREFIX.s() + "&cFailed to load up metrics."); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -0,0 +1,72 @@ | ||||
| package com.plotsquared.sponge; | ||||
|  | ||||
| import java.util.UUID; | ||||
| import java.util.concurrent.ExecutionException; | ||||
|  | ||||
| import com.intellectualcrafters.plot.object.OfflinePlotPlayer; | ||||
| import com.intellectualcrafters.plot.object.PlotPlayer; | ||||
| import com.intellectualcrafters.plot.util.UUIDHandler; | ||||
| import com.intellectualcrafters.plot.uuid.UUIDWrapper; | ||||
|  | ||||
| public class SpongeOnlineUUIDWrapper extends UUIDWrapper { | ||||
|  | ||||
|     @Override | ||||
|     public UUID getUUID(PlotPlayer player) { | ||||
|         return ((SpongePlayer) player).player.getUniqueId(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UUID getUUID(OfflinePlotPlayer player) { | ||||
|         return player.getUUID(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UUID getUUID(String name) { | ||||
|         try { | ||||
|             return SpongeMain.THIS.getResolver().get(name, true).get().getUniqueId(); | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) { | ||||
|         String name; | ||||
|         try { | ||||
|             name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName(); | ||||
|         } | ||||
|         catch (Exception e) { | ||||
|             name = null; | ||||
|         } | ||||
|         final String username = name; | ||||
|         return new OfflinePlotPlayer() { | ||||
|             @Override | ||||
|             public boolean isOnline() { | ||||
|                 return UUIDHandler.getPlayer(uuid) != null; | ||||
|             } | ||||
|              | ||||
|             @Override | ||||
|             public UUID getUUID() { | ||||
|                 return uuid; | ||||
|             } | ||||
|              | ||||
|             @Override | ||||
|             public String getName() { | ||||
|                 return username; | ||||
|             } | ||||
|              | ||||
|             @Override | ||||
|             public long getLastPlayed() { | ||||
|                 // TODO FIXME | ||||
|                 throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public OfflinePlotPlayer[] getOfflinePlayers() { | ||||
|         throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|     } | ||||
|      | ||||
| } | ||||
							
								
								
									
										205
									
								
								src/main/java/com/plotsquared/sponge/SpongePlayer.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										205
									
								
								src/main/java/com/plotsquared/sponge/SpongePlayer.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,205 @@ | ||||
| package com.plotsquared.sponge; | ||||
|  | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
| import java.util.UUID; | ||||
|  | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.permissions.Permission; | ||||
| import org.bukkit.permissions.PermissionDefault; | ||||
| import org.spongepowered.api.entity.player.Player; | ||||
| import org.spongepowered.api.text.chat.ChatTypes; | ||||
|  | ||||
| import com.flowpowered.math.vector.Vector3d; | ||||
| import com.intellectualcrafters.plot.commands.RequiredType; | ||||
| import com.intellectualcrafters.plot.config.C; | ||||
| import com.intellectualcrafters.plot.config.Settings; | ||||
| import com.intellectualcrafters.plot.object.Location; | ||||
| import com.intellectualcrafters.plot.object.PlotPlayer; | ||||
| import com.intellectualcrafters.plot.util.EconHandler; | ||||
| import com.intellectualcrafters.plot.util.MainUtil; | ||||
| import com.intellectualcrafters.plot.util.UUIDHandler; | ||||
|  | ||||
| public class SpongePlayer implements PlotPlayer { | ||||
|  | ||||
|     public final Player player; | ||||
|     private UUID uuid; | ||||
|     private String name; | ||||
|     private int op = 0; | ||||
|     private long last = 0; | ||||
|     private HashSet<String> hasPerm = new HashSet<>(); | ||||
|     private HashSet<String> noPerm = new HashSet<>(); | ||||
|      | ||||
|     private HashMap<String, Object> meta; | ||||
|  | ||||
|     public SpongePlayer(Player player) { | ||||
|         this.player = player; | ||||
|     } | ||||
|      | ||||
|     @Override | ||||
|     public void sendMessage(C c, String... args) { | ||||
|         MainUtil.sendMessage(this, c, args); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public RequiredType getSuperCaller() { | ||||
|         return RequiredType.PLAYER; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public long getPreviousLogin() { | ||||
|         return (long) (player.getJoinData().getLastPlayed().getSeconds()) * 1000; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Location getLocation() { | ||||
|         return SpongeUtil.getLocation(player); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Location getLocationFull() { | ||||
|         return SpongeUtil.getLocationFull(player); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UUID getUUID() { | ||||
|         if (this.uuid == null) { | ||||
|             this.uuid = UUIDHandler.getUUID(this); | ||||
|         } | ||||
|         return uuid; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean hasPermission(String perm) { | ||||
|         if (Settings.PERMISSION_CACHING) { | ||||
|             if (this.noPerm.contains(perm)) { | ||||
|                 return false; | ||||
|             } | ||||
|             if (this.hasPerm.contains(perm)) { | ||||
|                 return true; | ||||
|             } | ||||
|             final boolean result = this.player.hasPermission(perm); | ||||
|             if (!result) { | ||||
|                 this.noPerm.add(perm); | ||||
|                 return false; | ||||
|             } | ||||
|             this.hasPerm.add(perm); | ||||
|             return true; | ||||
|         } | ||||
|         return this.player.hasPermission(perm); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void sendMessage(String message) { | ||||
|         player.sendMessage(ChatTypes.CHAT, message); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void teleport(Location loc) { | ||||
|         String world = player.getWorld().getName(); | ||||
|         if (world != loc.getWorld()) { | ||||
|             player.transferToWorld(world, new Vector3d(loc.getX(), loc.getY(), loc.getZ())); | ||||
|         } | ||||
|         else { | ||||
|             org.spongepowered.api.world.Location current = player.getLocation(); | ||||
|             player.setLocationSafely(current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()))); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean isOp() { | ||||
|         if (this.op != 0) { | ||||
|             return this.op != 1; | ||||
|         } | ||||
|         final boolean result = this.player.hasPermission("*"); | ||||
|         if (!result) { | ||||
|             this.op = 1; | ||||
|             return false; | ||||
|         } | ||||
|         this.op = 2; | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean isOnline() { | ||||
|         return player.isOnline(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getName() { | ||||
|         if (this.name == null) { | ||||
|             this.name = this.player.getName(); | ||||
|         } | ||||
|         return this.name; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setCompassTarget(Location loc) { | ||||
|         // TODO set compass target | ||||
|         throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void loadData() { | ||||
|         // TODO Auto-generated method stub | ||||
|         throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void saveData() { | ||||
|         // TODO Auto-generated method stub | ||||
|         throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setMeta(String key, Object value) { | ||||
|         if (this.meta == null) { | ||||
|             this.meta = new HashMap<String, Object>(); | ||||
|         } | ||||
|         this.meta.put(key, value); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Object getMeta(String key) { | ||||
|         if (this.meta != null) { | ||||
|             return this.meta.get(key); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void deleteMeta(String key) { | ||||
|         if (this.meta != null) { | ||||
|             this.meta.remove(key); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return getName(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setAttribute(String key) { | ||||
|         key = "plotsquared_user_attributes." + key; | ||||
|         EconHandler.manager.setPermission(this, key, true); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean getAttribute(String key) { | ||||
|         key = "plotsquared_user_attributes." + key; | ||||
|         Permission perm = Bukkit.getServer().getPluginManager().getPermission(key); | ||||
|         if (perm == null) { | ||||
|             perm = new Permission(key, PermissionDefault.FALSE); | ||||
|             Bukkit.getServer().getPluginManager().addPermission(perm); | ||||
|             Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm); | ||||
|         } | ||||
|         return player.hasPermission(key); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removeAttribute(String key) { | ||||
|         key = "plotsquared_user_attributes." + key; | ||||
|         EconHandler.manager.setPermission(this, key, false); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										59
									
								
								src/main/java/com/plotsquared/sponge/SpongeTaskManager.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								src/main/java/com/plotsquared/sponge/SpongeTaskManager.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| package com.plotsquared.sponge; | ||||
|  | ||||
| import java.util.HashMap; | ||||
| import java.util.concurrent.atomic.AtomicInteger; | ||||
|  | ||||
| import org.spongepowered.api.service.scheduler.Task; | ||||
| import org.spongepowered.api.service.scheduler.TaskBuilder; | ||||
|  | ||||
| import com.intellectualcrafters.plot.util.TaskManager; | ||||
|  | ||||
| public class SpongeTaskManager extends TaskManager { | ||||
|  | ||||
|     private AtomicInteger i = new AtomicInteger(); | ||||
|      | ||||
|     private HashMap<Integer, Task> tasks = new HashMap<>(); | ||||
|      | ||||
|     @Override | ||||
|     public int taskRepeat(Runnable r, int interval) { | ||||
|         int val = i.incrementAndGet(); | ||||
|         TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); | ||||
|         TaskBuilder built = builder.delay(interval).interval(interval).execute(r); | ||||
|         Task task = built.submit(SpongeMain.THIS.getPlugin()); | ||||
|         tasks.put(val, task); | ||||
|         return val; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void taskAsync(Runnable r) { | ||||
|         TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); | ||||
|         builder.async().execute(r); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void task(Runnable r) { | ||||
|         TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); | ||||
|         builder.execute(r); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void taskLater(Runnable r, int delay) { | ||||
|         TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); | ||||
|         builder.delay(delay).execute(r); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void taskLaterAsync(Runnable r, int delay) { | ||||
|         TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); | ||||
|         builder.async().delay(delay).execute(r); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void cancelTask(int i) { | ||||
|         Task task = tasks.remove(i); | ||||
|         if (task != null) { | ||||
|             task.cancel(); | ||||
|         } | ||||
|     } | ||||
|      | ||||
| } | ||||
							
								
								
									
										53
									
								
								src/main/java/com/plotsquared/sponge/SpongeUUIDHandler.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/main/java/com/plotsquared/sponge/SpongeUUIDHandler.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| package com.plotsquared.sponge; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.UUID; | ||||
|  | ||||
| import org.spongepowered.api.GameProfile; | ||||
| import org.spongepowered.api.service.profile.GameProfileResolver; | ||||
|  | ||||
| import com.google.inject.Inject; | ||||
| import com.intellectualcrafters.plot.database.DBFunc; | ||||
| import com.intellectualcrafters.plot.object.RunnableVal; | ||||
| import com.intellectualcrafters.plot.object.StringWrapper; | ||||
| import com.intellectualcrafters.plot.util.TaskManager; | ||||
| import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; | ||||
| import com.intellectualcrafters.plot.uuid.UUIDWrapper; | ||||
|  | ||||
| public class SpongeUUIDHandler extends UUIDHandlerImplementation { | ||||
|  | ||||
|     public SpongeUUIDHandler(UUIDWrapper wrapper) { | ||||
|         super(wrapper); | ||||
|         // TODO Auto-generated constructor stub | ||||
|     } | ||||
|      | ||||
|     @Override | ||||
|     public boolean startCaching(Runnable whenDone) { | ||||
|         if (!super.startCaching(whenDone)) { | ||||
|             return false; | ||||
|         } | ||||
|         return cache(whenDone); | ||||
|     } | ||||
|  | ||||
|     public boolean cache(Runnable whenDone) { | ||||
|         // TODO cache UUIDS | ||||
| //        SpongeMain.THIS.getRegistry().get | ||||
|         add(new StringWrapper("*"), DBFunc.everyone); | ||||
|         for (GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) { | ||||
|             add(new StringWrapper(profile.getName()), profile.getUniqueId()); | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) { | ||||
|         TaskManager.runTaskAsync(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 ifFetch.value = uuidWrapper.getUUID(name); | ||||
|                 TaskManager.runTask(ifFetch); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|      | ||||
| } | ||||
							
								
								
									
										28
									
								
								src/main/java/com/plotsquared/sponge/SpongeUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/main/java/com/plotsquared/sponge/SpongeUtil.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| package com.plotsquared.sponge; | ||||
|  | ||||
| import org.spongepowered.api.entity.Entity; | ||||
|  | ||||
| import com.flowpowered.math.vector.Vector3d; | ||||
| import com.flowpowered.math.vector.Vector3i; | ||||
| import com.intellectualcrafters.plot.object.Location; | ||||
| import com.intellectualcrafters.plot.util.MathMan; | ||||
|  | ||||
| public class SpongeUtil { | ||||
|  | ||||
|     public static Location getLocation(Entity player) { | ||||
|         String world = player.getWorld().getName(); | ||||
|         org.spongepowered.api.world.Location loc = player.getLocation(); | ||||
|         Vector3i pos = loc.getBlockPosition(); | ||||
|         return new Location(world, pos.getX(), pos.getY(), pos.getZ()); | ||||
|     } | ||||
|      | ||||
|     public static Location getLocationFull(Entity player) { | ||||
|         String world = player.getWorld().getName(); | ||||
|         Vector3d rot = player.getRotation(); | ||||
|         float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ()); | ||||
|         org.spongepowered.api.world.Location loc = player.getLocation(); | ||||
|         Vector3i pos = loc.getBlockPosition(); | ||||
|         return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]); | ||||
|     } | ||||
|      | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 boy0001
					boy0001