org.spongepowered.common.SpongeImpl Java Examples

The following examples show how to use org.spongepowered.common.SpongeImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockPosCache.java    From GriefPrevention with MIT License 6 votes vote down vote up
public Tristate getCacheResult(short pos) {
    int currentTick = SpongeImpl.getServer().getTickCounter();
    if (this.lastBlockPos != pos) {
        this.lastBlockPos = pos;
        this.lastTickCounter = currentTick;
        return Tristate.UNDEFINED;
    }

    if ((currentTick - this.lastTickCounter) <= 2) {
        this.lastTickCounter = currentTick;
        return this.lastResult;
    }

    this.lastTickCounter = currentTick;
    return Tristate.UNDEFINED;
}
 
Example #2
Source File: PlayerStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public PlayerStorageData(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(PlayerDataConfig.class).bindToNew();

        load();
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #3
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order= Order.LAST)
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }

    GDTimings.PLAYER_QUIT_EVENT.startTimingIfSync();
    UUID playerID = player.getUniqueId();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);

    if (this.worldEditProvider != null) {
        this.worldEditProvider.revertVisuals(player, playerData, null);
        this.worldEditProvider.removePlayer(player);
    }

    playerData.onDisconnect();
    PaginationUtil.getInstance().removeActivePageData(player.getUniqueId());
    if (playerData.getClaims().isEmpty()) {
        this.dataStore.clearCachedPlayerData(player.getWorld().getUniqueId(), playerID);
    }
    GDCallbackHolder.getInstance().onPlayerDisconnect(player);
    GDTimings.PLAYER_QUIT_EVENT.stopTimingIfSync();
}
 
Example #4
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
    this.filePath = path;
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimTemplateConfig.class).bindToNew();

        reload();
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize claim template data", e);
    }
}
 
Example #5
Source File: MessageStorage.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(MessageDataConfig.class).bindToNew();

        reload();
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #6
Source File: WorldEventHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Listener(order = Order.EARLY, beforeModifications = true)
public void onWorldLoad(LoadWorldEvent event) {
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetWorld().getProperties())) {
        return;
    }

    GPTimings.WORLD_LOAD_EVENT.startTimingIfSync();
    GriefPreventionPlugin.instance.dataStore.loadWorldData(event.getTargetWorld());
    net.minecraft.world.World world = (net.minecraft.world.World) event.getTargetWorld();
    world.addEventListener(new EntityRemovalListener());
    GPTimings.WORLD_LOAD_EVENT.stopTimingIfSync();
    if (!GriefPreventionPlugin.getActiveConfig(event.getTargetWorld().getProperties()).getConfig().claim.bankTaxSystem) {
        return;
    }
    if (GriefPreventionPlugin.instance.economyService.isPresent()) {
        // run tax task
        TaxApplyTask taxTask = new TaxApplyTask(event.getTargetWorld().getProperties());
        int taxHour = GriefPreventionPlugin.getActiveConfig(event.getTargetWorld().getProperties()).getConfig().claim.taxApplyHour;
        long delay = TaskUtils.computeDelay(taxHour, 0, 0);
        Sponge.getScheduler().createTaskBuilder().delay(delay, TimeUnit.SECONDS).interval(1, TimeUnit.DAYS).execute(taxTask).submit(GriefPreventionPlugin.instance);
    }
}
 
Example #7
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bind(claimData);
        this.configMapper.getInstance().setClaimStorageData(this);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #8
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        if (path.getParent().endsWith("town")) {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(TownDataConfig.class).bindToNew();
        } else {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bindToNew();
        }
        this.configMapper.getInstance().setClaimStorageData(this);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #9
Source File: BlockPosCache.java    From GriefDefender with MIT License 6 votes vote down vote up
public Tristate getCacheResult(short pos) {
    int currentTick = SpongeImpl.getServer().getTickCounter();
    if (this.lastBlockPos != pos) {
        this.lastBlockPos = pos;
        this.lastTickCounter = currentTick;
        return Tristate.UNDEFINED;
    }

    if ((currentTick - this.lastTickCounter) <= 2) {
        this.lastTickCounter = currentTick;
        return this.lastResult;
    }

    this.lastTickCounter = currentTick;
    return Tristate.UNDEFINED;
}
 
Example #10
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, UUID ownerUniqueId, ClaimType type, boolean cuboid) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        if (type == ClaimType.TOWN) {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(TownDataConfig.class).bindToNew();
        } else {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bindToNew();
        }
        this.configMapper.getInstance().setWorldUniqueId(worldUniqueId);
        this.configMapper.getInstance().setOwnerUniqueId(ownerUniqueId);
        this.configMapper.getInstance().setType(type);
        this.configMapper.getInstance().setCuboid(cuboid);
        this.configMapper.getInstance().setClaimStorageData(this);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(Sponge.getServer().getWorld(worldUniqueId).get().getProperties());
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #11
Source File: MessageStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults()
                .setHeader(GriefPreventionPlugin.CONFIG_HEADER));
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #12
Source File: MessageStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void save() {
    try {
        this.configMapper.serialize(this.root.getNode(GriefPreventionPlugin.MOD_ID));
        this.loader.save(this.root);
    } catch (IOException | ObjectMappingException e) {
        SpongeImpl.getLogger().error("Failed to save configuration", e);
    }
}
 
Example #13
Source File: PlayerStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void load() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #14
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void save() {
    try {
        this.configMapper.serialize(this.root.getNode(GriefPreventionPlugin.MOD_ID));
        this.loader.save(this.root);
        this.configBase.setRequiresSave(false);
    } catch (IOException | ObjectMappingException e) {
        SpongeImpl.getLogger().error("Failed to save configuration", e);
    }
}
 
Example #15
Source File: PlayerStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void save() {
    try {
        if (this.configBase != null) {
            if (this.configBase.requiresSave()) {
                this.configMapper.serialize(this.root.getNode(GriefPreventionPlugin.MOD_ID));
                this.loader.save(this.root);
                this.configBase.setRequiresSave(false);
            }
        }
    } catch (IOException | ObjectMappingException e) {
        SpongeImpl.getLogger().error("Failed to save configuration", e);
    }
}
 
Example #16
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void load() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #17
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void save() {
    try {
        this.configMapper.serialize(this.root.getNode(GriefPreventionPlugin.MOD_ID));
        this.loader.save(this.root);
    } catch (IOException | ObjectMappingException e) {
        SpongeImpl.getLogger().error("Failed to save configuration", e);
    }
}
 
Example #18
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults()
                .setSerializers(
                        TypeSerializers.getDefaultSerializers().newChild().registerType(TypeToken.of(IpSet.class), new IpSet.IpSetSerializer()))
                .setHeader(GriefPreventionPlugin.CONFIG_HEADER));
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #19
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(String templateName, Optional<String> description, IClaimData claimData, UUID creator) {
    this.filePath = FlatFileDataStore.rootWorldSavePath.resolve(FlatFileDataStore.claimTemplatePath.resolve(UUID.randomUUID().toString()));
    try {
        if (Files.notExists(this.filePath.getParent())) {
            Files.createDirectories(this.filePath.getParent());
        }
        if (Files.notExists(this.filePath)) {
            Files.createFile(this.filePath);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(this.filePath).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimTemplateConfig.class).bindToNew();

        reload();
        this.configBase.templateName = templateName;
        if (description.isPresent()) {
            this.configBase.templateDescription = description.get();
        }
        this.configBase.ownerUniqueId = creator;
        this.configBase.accessors = new ArrayList<UUID>(claimData.getAccessors());
        this.configBase.builders = new ArrayList<UUID>(claimData.getBuilders());
        this.configBase.containers = new ArrayList<UUID>(claimData.getContainers());
        this.configBase.coowners = new ArrayList<UUID>(claimData.getManagers());
        //this.configBase.flags = new HashMap<String, Tristate>(claimData.getFlags());
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize claim template data", e);
    }
}
 
Example #20
Source File: GPPlayerData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public boolean checkLastInteraction(GPClaim claim, User user) {
    if (this.lastInteractResult && user != null && ((SpongeImpl.getServer().getTickCounter() - this.lastTickCounter) <= 2)) {
        if (claim.getUniqueId().equals(this.lastInteractClaim) || claim.isWilderness()) {
            return true;
        }
    }

    return false;
}
 
Example #21
Source File: WorldEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onWorldUnload(UnloadWorldEvent event) {
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetWorld().getProperties())) {
        return;
    }

    GriefPreventionPlugin.instance.dataStore.removeClaimWorldManager(event.getTargetWorld().getProperties());
}
 
Example #22
Source File: WorldEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.EARLY)
public void onConstructWorldProperties(ConstructWorldPropertiesEvent event) {
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getWorldProperties())) {
        return;
    }

    GriefPreventionPlugin.instance.dataStore.registerWorld(event.getWorldProperties());
}
 
Example #23
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onPlayerKicked(KickPlayerEvent event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_KICK_EVENT.startTimingIfSync();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    playerData.wasKicked = true;
    GPTimings.PLAYER_KICK_EVENT.stopTimingIfSync();
}
 
Example #24
Source File: WorldEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onWorldUnload(UnloadWorldEvent event) {
    if (!SpongeImpl.getServer().isServerRunning() || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetWorld().getUniqueId())) {
        return;
    }

    GriefDefenderPlugin.getInstance().dataStore.removeClaimWorldManager(event.getTargetWorld().getProperties());
}
 
Example #25
Source File: WorldEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.EARLY, beforeModifications = true)
public void onWorldLoad(LoadWorldEvent event) {
    if (!SpongeImpl.getServer().isServerRunning() || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetWorld().getUniqueId())) {
        return;
    }

    GDTimings.WORLD_LOAD_EVENT.startTimingIfSync();
    GriefDefenderPlugin.getInstance().dataStore.registerWorld(event.getTargetWorld());
    GriefDefenderPlugin.getInstance().dataStore.loadWorldData(event.getTargetWorld());
    NMSUtil.getInstance().addEntityRemovalListener(event.getTargetWorld());
    GDTimings.WORLD_LOAD_EVENT.stopTimingIfSync();
}
 
Example #26
Source File: GPPlayerData.java    From GriefPrevention with MIT License 4 votes vote down vote up
public void setLastInteractData(GPClaim claim) {
    this.lastInteractResult = true;
    this.lastInteractClaim = claim.getUniqueId();
    this.lastTickCounter = SpongeImpl.getServer().getTickCounter();
}
 
Example #27
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order= Order.LAST)
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_QUIT_EVENT.startTimingIfSync();
    UUID playerID = player.getUniqueId();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);
    boolean isBanned = false;
    if (playerData.wasKicked) {
        isBanned = this.banService.isBanned(player.getProfile()) || (playerData.ipAddress != null && this.banService.isBanned(playerData.ipAddress));
    }

    // if banned, add IP to the temporary IP ban list
    if (isBanned && playerData.ipAddress != null) {
        long now = Calendar.getInstance().getTimeInMillis();
        this.tempBannedIps.add(new IpBanInfo(playerData.ipAddress, now + this.MILLISECONDS_IN_DAY, player.getName()));
    }

    // silence notifications when they're coming too fast, or the player is banned
    if (this.shouldSilenceNotification() || isBanned) {
        event.setMessage(Text.of());
    } else {
        // make sure his data is all saved - he might have accrued some claim
        // blocks while playing that were not saved immediately
        playerData.saveAllData();
    }

    // FEATURE: players in pvp combat when they log out will die
    if (GriefPreventionPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().pvp.punishPvpLogout && playerData.inPvpCombat(player.getWorld())) {
        player.offer(Keys.HEALTH, 0d);
    }

    if (this.worldEditProvider != null) {
        this.worldEditProvider.revertVisuals(player, playerData, null);
        this.worldEditProvider.removePlayer(player);
    }

    playerData.onDisconnect();
    PaginationUtils.removeActivePageData(player.getUniqueId());
    if (playerData.getClaims().isEmpty()) {
        this.dataStore.clearCachedPlayerData(player.getWorld().getProperties(), playerID);
    }

    // reduce count of players with that player's IP address
    // TODO: re-enable when achievement data is implemented
    /*if (GriefPrevention.instance.config_ipLimit > 0 && !player.getAchievementData().achievements().contains(Achievements.MINE_WOOD)) {
        InetAddress ipAddress = playerData.ipAddress;
        if (ipAddress != null) {
            String ipAddressString = ipAddress.toString();
            Integer count = this.ipCountHash.get(ipAddressString);
            if (count == null)
                count = 1;
            this.ipCountHash.put(ipAddressString, count - 1);
        }
    }*/
    GPTimings.PLAYER_QUIT_EVENT.stopTimingIfSync();
}
 
Example #28
Source File: ImplementationConfig.java    From ChatUI with MIT License 4 votes vote down vote up
@Override
public ConfigurationNode rootNode() {
    return SpongeImpl.getGlobalConfig().getRootNode();
}
 
Example #29
Source File: BlockPosCache.java    From GriefDefender with MIT License 4 votes vote down vote up
public BlockPosCache(short pos) {
    this.lastBlockPos = pos;
    this.lastTickCounter = SpongeImpl.getServer().getTickCounter();
}
 
Example #30
Source File: BlockPosCache.java    From GriefPrevention with MIT License 4 votes vote down vote up
public BlockPosCache(short pos) {
    this.lastBlockPos = pos;
    this.lastTickCounter = SpongeImpl.getServer().getTickCounter();
}