mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-26 02:34:42 +02:00
Various
sponge changes / documentation / cleanup / event tweak
This commit is contained in:
@ -44,13 +44,16 @@ import org.spongepowered.api.world.gen.WorldGenerator;
|
||||
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by robin on 01/11/2014
|
||||
*/
|
||||
|
||||
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.3.1", dependencies = "before:WorldEdit")
|
||||
@Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.1")
|
||||
public class SpongeMain implements IPlotMain {
|
||||
public static SpongeMain THIS;
|
||||
|
||||
@ -86,33 +89,6 @@ public class SpongeMain implements IPlotMain {
|
||||
return THIS;
|
||||
}
|
||||
|
||||
// @Override
|
||||
public String getId() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
// @Override
|
||||
public Optional<Object> getInstance() {
|
||||
return Optional.<Object> of(THIS);
|
||||
}
|
||||
|
||||
// @Override
|
||||
public String getName() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
// @Override
|
||||
public String getVersion() {
|
||||
final int[] version = PS.get().getVersion();
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
for (final int i : version) {
|
||||
result += prefix + i;
|
||||
prefix = ".";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void init(final GameInitializationEvent event) {
|
||||
log("PlotSquared: Game init");
|
||||
@ -163,8 +139,8 @@ public class SpongeMain implements IPlotMain {
|
||||
|
||||
@Override
|
||||
public int[] getPluginVersion() {
|
||||
final PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get();
|
||||
final String version = plugin.getVersion();
|
||||
PluginContainer plugin = game.getPluginManager().fromInstance(this).get();
|
||||
String version = plugin.getVersion().get();
|
||||
log("Checking plugin version: PlotSquared: ");
|
||||
final String[] split = version.split("\\.");
|
||||
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
|
||||
|
@ -120,7 +120,6 @@ public class MainListener {
|
||||
final String sender = player.getName();
|
||||
final PlotId id = plot.getId();
|
||||
final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
|
||||
final Text forcedMessage = event.getMessage();
|
||||
// String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
PlotPlayer user = entry.getValue();
|
||||
@ -128,7 +127,7 @@ public class MainListener {
|
||||
if (plot.equals(user.getLocation().getPlot())) {
|
||||
toSend = newMessage;
|
||||
} else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) {
|
||||
((SpongePlayer) user).player.sendMessage(forcedMessage);
|
||||
((SpongePlayer) user).player.sendMessage(message);
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
@ -146,7 +145,7 @@ public class MainListener {
|
||||
}
|
||||
((SpongePlayer) user).player.sendMessage(Text.join(components));
|
||||
}
|
||||
event.clearMessage();
|
||||
event.setMessage(null);
|
||||
}
|
||||
|
||||
@Listener
|
||||
|
@ -131,7 +131,7 @@ public class SpongePlayer extends PlotPlayer {
|
||||
@Override
|
||||
public void setCompassTarget(final Location loc) {
|
||||
final TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
|
||||
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc));
|
||||
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc).getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,22 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
|
||||
import org.spongepowered.api.service.economy.EconomyService;
|
||||
import org.spongepowered.api.service.economy.account.UniqueAccount;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
|
||||
import org.spongepowered.api.service.economy.EconomyService;
|
||||
import org.spongepowered.api.service.economy.account.UniqueAccount;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeEconHandler extends EconHandler {
|
||||
private EconomyService econ;
|
||||
|
||||
|
||||
public SpongeEconHandler() {
|
||||
if (Sponge.getServiceManager().isRegistered(EconomyService.class)) {
|
||||
econ = Sponge.getServiceManager().provide(EconomyService.class).get();
|
||||
@ -35,11 +33,11 @@ public class SpongeEconHandler extends EconHandler {
|
||||
@Override
|
||||
public void withdrawMoney(PlotPlayer player, double amount) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
|
||||
acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
|
||||
acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,10 +45,10 @@ public class SpongeEconHandler extends EconHandler {
|
||||
@Override
|
||||
public void depositMoney(PlotPlayer player, double amount) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
|
||||
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,10 +56,10 @@ public class SpongeEconHandler extends EconHandler {
|
||||
@Override
|
||||
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
|
||||
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,7 +83,7 @@ public class SpongeEconHandler extends EconHandler {
|
||||
@Override
|
||||
public double getBalance(PlotPlayer player) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
BigDecimal balance = acc.getBalance(econ.getDefaultCurrency());
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.ItemType;
|
||||
import org.spongepowered.api.item.ItemTypes;
|
||||
@ -11,12 +15,7 @@ import org.spongepowered.api.item.inventory.custom.CustomInventory;
|
||||
import org.spongepowered.api.item.inventory.property.SlotIndex;
|
||||
import org.spongepowered.api.item.inventory.type.CarriedInventory;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SpongeInventoryUtil extends InventoryUtil {
|
||||
|
||||
@ -41,7 +40,7 @@ public class SpongeInventoryUtil extends InventoryUtil {
|
||||
}
|
||||
}
|
||||
inv.player.setMeta("inventory", inv);
|
||||
player.openInventory(inventory);
|
||||
player.openInventory(inventory, SpongeUtil.CAUSE);
|
||||
}
|
||||
|
||||
public ItemStack getItem(final PlotItemStack item) {
|
||||
@ -56,7 +55,7 @@ public class SpongeInventoryUtil extends InventoryUtil {
|
||||
}
|
||||
inv.player.deleteMeta("inventory");
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
sp.player.closeInventory();
|
||||
sp.player.closeInventory(SpongeUtil.CAUSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,8 @@ package com.plotsquared.sponge.util;
|
||||
* either expressed or implied, of anybody else.
|
||||
*/
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -42,18 +44,13 @@ import java.net.URLEncoder;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
||||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
||||
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
public class SpongeMetrics {
|
||||
|
||||
/**
|
||||
@ -404,7 +401,7 @@ public class SpongeMetrics {
|
||||
// Server software specific section
|
||||
final String pluginName = plugin.getName();
|
||||
final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
final String pluginVersion = plugin.getVersion();
|
||||
final String pluginVersion = plugin.getVersion().get();
|
||||
// TODO no visible way to get MC version at the moment
|
||||
// TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1
|
||||
final String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion());
|
||||
|
@ -32,6 +32,7 @@ import org.spongepowered.api.data.value.mutable.ListValue;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.cause.NamedCause;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import org.spongepowered.api.text.translation.Translation;
|
||||
@ -49,7 +50,9 @@ import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeUtil extends WorldUtil {
|
||||
|
||||
|
||||
public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared"));
|
||||
|
||||
public static Location getLocation(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
|
@ -1,17 +1,16 @@
|
||||
package com.plotsquared.sponge.uuid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@ -36,7 +35,7 @@ public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
|
||||
try {
|
||||
final GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
|
||||
if (profile != null) {
|
||||
name = profile.getName();
|
||||
name = profile.getName().orElse(null);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -44,9 +43,12 @@ public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
|
||||
}
|
||||
if (name == null) {
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
|
||||
if (getUUID(profile.getName()).equals(uuid)) {
|
||||
name = profile.getName();
|
||||
break;
|
||||
String tmp = profile.getName().orElse(null);
|
||||
if (tmp != null) {
|
||||
if (getUUID(name).equals(uuid)) {
|
||||
name = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.plotsquared.sponge.uuid;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
@ -9,6 +7,8 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@Override
|
||||
@ -35,7 +35,7 @@ public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
|
||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
||||
String name;
|
||||
try {
|
||||
name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName();
|
||||
name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName().orElse(null);
|
||||
} catch (final Exception e) {
|
||||
name = null;
|
||||
}
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.plotsquared.sponge.uuid;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
@ -11,6 +7,9 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeUUIDHandler extends UUIDHandlerImplementation {
|
||||
|
||||
@ -29,7 +28,10 @@ public class SpongeUUIDHandler extends UUIDHandlerImplementation {
|
||||
public boolean cache(final Runnable whenDone) {
|
||||
add(new StringWrapper("*"), DBFunc.everyone);
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
|
||||
add(new StringWrapper(profile.getName()), profile.getUniqueId());
|
||||
String name = profile.getName().orElse(null);
|
||||
if (name != null) {
|
||||
add(new StringWrapper(name), profile.getUniqueId());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user